From ac0d86ac0938436fecafe054470ac9a89d9c78f7 Mon Sep 17 00:00:00 2001 From: waterliu99 Date: Thu, 27 Jun 2024 23:05:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0gps51=E9=99=84=E5=8A=A0?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JT808.Protocol.Extensions.GPS51.xml | 501 +++++++++++++++++- .../JT808_GPS51_Constants.cs | 24 +- .../MessageBody/JT808_0x0200_0x54.cs | 103 ++++ .../MessageBody/JT808_0x0200_0x55.cs | 69 +++ .../MessageBody/JT808_0x0200_0x58.cs | 92 ++++ .../MessageBody/JT808_0x0200_0x61.cs | 75 +++ .../MessageBody/JT808_0x0200_0xe1.cs | 139 +++++ .../MessageBody/JT808_0x0200_0xe2.cs | 78 +++ .../MessageBody/JT808_0x0200_0xf1.cs | 79 +++ .../MessageBody/JT808_0x0200_0xf6.cs | 78 +++ .../MessageBody/JT808_0x0200_0xfa.cs | 94 ++++ .../MessageBody/JT808_0x0200_0xfb.cs | 92 ++++ 12 files changed, 1417 insertions(+), 7 deletions(-) create mode 100644 src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x54.cs create mode 100644 src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x55.cs create mode 100644 src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x58.cs create mode 100644 src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x61.cs create mode 100644 src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xe1.cs create mode 100644 src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xe2.cs create mode 100644 src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xf1.cs create mode 100644 src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xf6.cs create mode 100644 src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xfa.cs create mode 100644 src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xfb.cs diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/JT808.Protocol.Extensions.GPS51.xml b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/JT808.Protocol.Extensions.GPS51.xml index 0788610..2310610 100644 --- a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/JT808.Protocol.Extensions.GPS51.xml +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/JT808.Protocol.Extensions.GPS51.xml @@ -171,12 +171,28 @@ 解析结果:电量百分比5F=95 电压:0507=1287 最终显示为12.87V 01:充电中 - + - + 锁车 + + + + + + 解锁车 恢复油电 + + + 设防 + + + + + 撤防 + + 多路油耗模拟量 @@ -310,6 +326,487 @@ + + + 1+7*N + Wifi数据:第1个字节wifi个数,后面为n个wifi数据;WIFI数据:6字节 wifiMac 1字节 信号强度 + + + + + + + + + + + + + + + wifi个数 + + + + + wifi信息 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 信号轻度 + + + + + 8 + 1/10千克 8 字节 载重扩展 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2*N + 湿度,精度0.1,0fff 代表无效数据,例子数据: 0012 表示:1.8% + + + + + + + + + + + + + + + 湿度 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 电压,单位0.01V,例子报文:61021d74,解析结果7540,最终电压75.40V + + + + + + + + + + + + + + + 电压 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 4+7*N + 基站编码的格式为 MCC MNC LAC CI Signal 2-2-2-4-1-2-4-1,其中MCC 2个字节国家编码,MNC 为 2个字节网络编码, + LAC为 2个字节地区编码,CI 为 4个字节蜂窝 ID, 信号强度 1字节,单基站可以不用信号强度 1cc-0-696a-863a8d0-0 + + + + + + + + + + + + + + + 国家编码 + + + + + 网络编码 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 地区编码 + + + + + 蜂窝 ID + + + + + 信号强度 + + + + + N + 版本号,开机或者重连第一条上报,例子结果:GB201-GSM-21001-1.1.1 + + + + + + + + + + + + + + + 版本号 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 20 + iccid,一般开机或者重连第一条0200位置信息上报, + 例子报文:f1143839383630343032313032303930393737303032,解析结果为:89860402102090977002 + + + + + + + + + + + + + + + ICCID + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IMEI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 4 + 第0位:震动报警 + 第1位:拆除报警 + 例子:第0位:震动报警 fa0400000001 第1位:拆除报警 fa0400000002 第2位:进入深度休眠 fa0400000004 第3位:急加速 fa0400000008 + 第4位:急减速 fa0400000010 第5位:急转弯 fa0400000020 第6位:acc开报警 fa0400000040 第7位:acc关报警 fa0400000080 + 第8位:内部电池电量低fa0400000100 第9位:人为关机 fa0400000200 第10位:低电关机 fa0400000400 第11位:设防(状态) fa0400000800 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 4 + 电量百分比和外部电压,电压精度0.01V,充电状态0未充电 1充电中,没有的数据传00 + 例子:fb045F050701 解析结果:电量百分比5F=95 电压:0507=1287 最终显示为12.87V 01:充电中 + + + + + + + + + + + + + + + 电量百分比 + + + + + 电压 + + + + + 状态 + + + + + + + + + + + + + + + + + + + + + + + + + + 报警标识号 diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/JT808_GPS51_Constants.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/JT808_GPS51_Constants.cs index 217ec79..6e73cf3 100644 --- a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/JT808_GPS51_Constants.cs +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/JT808_GPS51_Constants.cs @@ -43,19 +43,19 @@ namespace JT808.Protocol.Extensions.GPS51 /// 载重扩展 8 /// 1/10千克 8 字节 /// - public const uint JT808_0x0200_0x55 = 0x55; + public const byte JT808_0x0200_0x55 = 0x55; /// /// 湿度, /// 2*N /// 精度0.1,0fff 代表无效数据,例子数据: 0012 表示:1.8% /// - public const uint JT808_0x0200_0x58 = 0x58; + public const byte JT808_0x0200_0x58 = 0x58; /// /// 电压, /// 2 /// 单位0.01V,例子报文:61021d74,解析结果7540,最终电压75.40V /// - public const uint JT808_0x0200_0x61 = 0x61; + public const byte JT808_0x0200_0x61 = 0x61; /// /// 基站编码 /// 4+7*N @@ -65,7 +65,7 @@ namespace JT808.Protocol.Extensions.GPS51 /// 信号强度 1字节, /// 单基站可以不用信号强度 1cc-0-696a-863a8d0-0 /// - public const uint JT808_0x0200_0xe1 = 0xe1; + public const byte JT808_0x0200_0xe1 = 0xe1; /// /// 版本号, /// N @@ -110,9 +110,23 @@ namespace JT808.Protocol.Extensions.GPS51 /// public const byte JT808_0x0200_0xfb = 0xfb; /// - /// + /// 锁车 /// /// + public const byte JT808_0x8105_0x64 = 0x64; + /// + /// 解锁车 恢复油电 + /// + /// + public const byte JT808_0x8105_0x65= 0x65; + /// + /// 设防 + /// + public const byte JT808_0x8105_0xA0 = 0xA0; + /// + /// 撤防 + /// + public const byte JT808_0x8105_0xA1 = 0xA1; public static Assembly GetCurrentAssembly() { return Assembly.GetExecutingAssembly(); diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x54.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x54.cs new file mode 100644 index 0000000..f2f8482 --- /dev/null +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x54.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Emit; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.GPS51.Metadata; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessageBody; +using JT808.Protocol.MessagePack; + +namespace JT808.Protocol.Extensions.GPS51.MessageBody +{ + /// + /// 1+7*N + /// Wifi数据:第1个字节wifi个数,后面为n个wifi数据;WIFI数据:6字节 wifiMac 1字节 信号强度 + /// + public class JT808_0x0200_0x54 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + { + /// + /// + /// + public byte AttachInfoId { get; set; } = JT808_GPS51_Constants.JT808_0x0200_0x54; + /// + /// + /// + public byte AttachInfoLength { get; set; } + /// + /// wifi个数 + /// + public byte Count { get; set; } + /// + /// wifi信息 + /// + public List WifiInfos { get; set; } + /// + /// + /// + /// + /// + /// + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x54 value = new JT808_0x0200_0x54(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.Count = reader.ReadByte(); + for (int i = 0; i < value.Count; i++) + { + + // writer.WriteString($"[{value.Direction.ReadNumber()}]正反转", "未知"); + + } + } + /// + /// + /// + /// + /// + /// + public override JT808_0x0200_0x54 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) + { + JT808_0x0200_0x54 value = new JT808_0x0200_0x54(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.Count = reader.ReadByte(); + for (int i = 0; i < value.Count; i++) + { + + // + + } + return value; + } + /// + /// + /// + /// + /// + /// + public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x54 value, IJT808Config config) + { + writer.WriteByte(value.AttachInfoId); + writer.WriteByte(1); + writer.WriteByte((byte)value.WifiInfos.Count); + foreach (var wifi in value.WifiInfos) + { + + } + } + } + + public class WifiInfo { + + /// + /// 信号轻度 + /// + public byte SingnalStrength { get; set; } + } +} diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x55.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x55.cs new file mode 100644 index 0000000..8ceef40 --- /dev/null +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x55.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.GPS51.Metadata; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessageBody; +using JT808.Protocol.MessagePack; + +namespace JT808.Protocol.Extensions.GPS51.MessageBody +{ + /// + /// 8 + /// 1/10千克 8 字节 载重扩展 + /// + public class JT808_0x0200_0x55 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + { + /// + /// + /// + public byte AttachInfoId { get; set; } = JT808_GPS51_Constants.JT808_0x0200_0x55; + /// + /// + /// + public byte AttachInfoLength { get; set; } + + /// + /// + /// + /// + /// + /// + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x55 value = new JT808_0x0200_0x55(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + + } + /// + /// + /// + /// + /// + /// + public override JT808_0x0200_0x55 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) + { + JT808_0x0200_0x55 value = new JT808_0x0200_0x55(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + return value; + } + /// + /// + /// + /// + /// + /// + public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x55 value, IJT808Config config) + { + writer.WriteByte(value.AttachInfoId); + writer.WriteByte(1); + } + } +} diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x58.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x58.cs new file mode 100644 index 0000000..560fec4 --- /dev/null +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x58.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.ConstrainedExecution; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.GPS51.Metadata; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessageBody; +using JT808.Protocol.MessagePack; + +namespace JT808.Protocol.Extensions.GPS51.MessageBody +{ + /// + /// 2*N + /// 湿度,精度0.1,0fff 代表无效数据,例子数据: 0012 表示:1.8% + /// + public class JT808_0x0200_0x58 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + { + /// + /// + /// + public byte AttachInfoId { get; set; } = JT808_GPS51_Constants.JT808_0x0200_0x58; + /// + /// + /// + public byte AttachInfoLength { get; set; } + /// + /// 湿度 + /// + public List Humiditys { get; set; } + /// + /// + /// + /// + /// + /// + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x58 value = new JT808_0x0200_0x58(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + writer.WriteNumber($"[{reader.ReadContent(value.AttachInfoLength).ToArray().ToHexString()}]湿度列表", value.AttachInfoLength / 2); + writer.WriteStartArray(); + while (reader.ReadCurrentRemainContentLength() > 0) { + writer.WriteNumber($"[{reader.ReadUInt16().ReadNumber()}]附加信息长度", reader.ReadUInt16()); + } + writer.WriteStartArray(); + + } + /// + /// + /// + /// + /// + /// + public override JT808_0x0200_0x58 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) + { + JT808_0x0200_0x58 value = new JT808_0x0200_0x58(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.Humiditys = new List(); + while (reader.ReadCurrentRemainContentLength() > 0) + { + value.Humiditys.Add(reader.ReadUInt16()); + } + return value; + } + /// + /// + /// + /// + /// + /// + public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x58 value, IJT808Config config) + { + writer.WriteByte(value.AttachInfoId); + writer.Skip(1,out int position); + foreach (var humidity in value.Humiditys) + { + writer.WriteUInt16(humidity); + } + int length = writer.GetCurrentPosition() - position - 1; + writer.WriteByteReturn((byte)length, position); + } + } + + +} diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x61.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x61.cs new file mode 100644 index 0000000..5952300 --- /dev/null +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0x61.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.GPS51.Metadata; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessageBody; +using JT808.Protocol.MessagePack; + +namespace JT808.Protocol.Extensions.GPS51.MessageBody +{ + /// + /// 电压,单位0.01V,例子报文:61021d74,解析结果7540,最终电压75.40V + /// + public class JT808_0x0200_0x61 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + { + /// + /// + /// + public byte AttachInfoId { get; set; } = JT808_GPS51_Constants.JT808_0x0200_0x61; + /// + /// + /// + public byte AttachInfoLength { get; set; } + /// + /// 电压 + /// + public ushort Volage { get; set; } + + /// + /// + /// + /// + /// + /// + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x61 value = new JT808_0x0200_0x61(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.Volage = reader.ReadUInt16(); + writer.WriteNumber($"[{value.Volage.ReadNumber()}]电压", value.Volage); + } + /// + /// + /// + /// + /// + /// + public override JT808_0x0200_0x61 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) + { + JT808_0x0200_0x61 value = new JT808_0x0200_0x61(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.Volage = reader.ReadUInt16(); + return value; + } + /// + /// + /// + /// + /// + /// + public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x61 value, IJT808Config config) + { + writer.WriteByte(value.AttachInfoId); + writer.WriteByte(1); + writer.WriteUInt16(value.Volage); + } + } +} diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xe1.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xe1.cs new file mode 100644 index 0000000..8fa3c13 --- /dev/null +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xe1.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.GPS51.Metadata; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessageBody; +using JT808.Protocol.MessagePack; + +namespace JT808.Protocol.Extensions.GPS51.MessageBody +{ + /// + /// 4+7*N + /// 基站编码的格式为 MCC MNC LAC CI Signal 2-2-2-4-1-2-4-1,其中MCC 2个字节国家编码,MNC 为 2个字节网络编码, + /// LAC为 2个字节地区编码,CI 为 4个字节蜂窝 ID, 信号强度 1字节,单基站可以不用信号强度 1cc-0-696a-863a8d0-0 + /// + public class JT808_0x0200_0xe1 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + { + /// + /// + /// + public byte AttachInfoId { get; set; } = JT808_GPS51_Constants.JT808_0x0200_0xe1; + /// + /// + /// + public byte AttachInfoLength { get; set; } + /// + /// 国家编码 + /// + public ushort MCC { get; set; } + /// + /// 网络编码 + /// + public ushort MNC { get; set; } + + public List BaseStations { get; set; } + /// + /// + /// + /// + /// + /// + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0xe1 value = new JT808_0x0200_0xe1(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.MCC = reader.ReadUInt16(); + writer.WriteNumber($"[{value.MCC.ReadNumber()}]国家编码", value.MCC); + value.MNC=reader.ReadUInt16(); + writer.WriteNumber($"[{value.MNC.ReadNumber()}]网络编码", value.MNC); + writer.WriteStartArray("地区编码列表"); + while (reader.ReadCurrentRemainContentLength() > 0) + { + var LAC = reader.ReadUInt16(); + writer.WriteNumber($"[{LAC.ReadNumber()}]地区编码", LAC); + var CI = reader.ReadUInt32(); + writer.WriteNumber($"[{CI.ReadNumber()}]蜂窝 ID", CI); + if (reader.ReadCurrentRemainContentLength() > 0) + { + var Signal = reader.ReadByte(); + writer.WriteNumber($"[{Signal.ReadNumber()}]信号强度", Signal); + } + } + writer.WriteEndArray(); + + } + /// + /// + /// + /// + /// + /// + public override JT808_0x0200_0xe1 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) + { + JT808_0x0200_0xe1 value = new JT808_0x0200_0xe1(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + if (value.AttachInfoLength > 0) { + value.MCC = reader.ReadUInt16(); + value.MNC = reader.ReadUInt16(); + value.BaseStations = new List(); + while (reader.ReadCurrentRemainContentLength()> 0) + { + BaseStation baseStation = new BaseStation(); + baseStation.LAC = reader.ReadUInt16(); + baseStation.CI = reader.ReadUInt32(); + if (reader.ReadCurrentRemainContentLength() > 0) { + baseStation.Signal=reader.ReadByte(); + } + value.BaseStations.Add(baseStation); + } + } + return value; + } + /// + /// + /// + /// + /// + /// + public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0xe1 value, IJT808Config config) + { + writer.WriteByte(value.AttachInfoId); + writer.Skip(1,out int position); + writer.WriteUInt16(value.MCC); + writer.WriteUInt16(value.MNC); + foreach (var baseStation in value.BaseStations) + { + writer.WriteUInt16(baseStation.LAC); + writer.WriteUInt32(baseStation.CI); + if (value.BaseStations.Count >1) { + writer.WriteByte(baseStation.Signal); + } + } + var length = writer.GetCurrentPosition() - position - 1; + writer.WriteByteReturn((byte)length, position); + } + } + + public class BaseStation() { + /// + /// 地区编码 + /// + public ushort LAC { get; set; } + /// + /// 蜂窝 ID + /// + public uint CI { get; set; } + /// + /// 信号强度 + /// + public byte Signal { get; set; } + } +} diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xe2.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xe2.cs new file mode 100644 index 0000000..70dd5d2 --- /dev/null +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xe2.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.GPS51.Metadata; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessageBody; +using JT808.Protocol.MessagePack; + +namespace JT808.Protocol.Extensions.GPS51.MessageBody +{ + /// + /// N + /// 版本号,开机或者重连第一条上报,例子结果:GB201-GSM-21001-1.1.1 + /// + public class JT808_0x0200_0xe2 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + { + /// + /// + /// + public byte AttachInfoId { get; set; } = JT808_GPS51_Constants.JT808_0x0200_0xe2; + /// + /// + /// + public byte AttachInfoLength { get; set; } + /// + /// 版本号 + /// + public string Version { get; set; } + + /// + /// + /// + /// + /// + /// + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0xe2 value = new JT808_0x0200_0xe2(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + var version = reader.ReadVirtualArray(value.AttachInfoLength); + writer.WriteString($"[{version.ToArray().ToHexString()}]版本号", reader.ReadRemainStringContent()); + } + /// + /// + /// + /// + /// + /// + public override JT808_0x0200_0xe2 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) + { + JT808_0x0200_0xe2 value = new JT808_0x0200_0xe2(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.Version = reader.ReadRemainStringContent(); + return value; + } + /// + /// + /// + /// + /// + /// + public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0xe2 value, IJT808Config config) + { + writer.WriteByte(value.AttachInfoId); + writer.Skip(1,out int position); + writer.WriteString(value.Version); + var length = writer.GetCurrentPosition() - position - 1; + writer.WriteByteReturn((byte)length, position); + } + } +} diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xf1.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xf1.cs new file mode 100644 index 0000000..a094211 --- /dev/null +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xf1.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.GPS51.Metadata; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessageBody; +using JT808.Protocol.MessagePack; + +namespace JT808.Protocol.Extensions.GPS51.MessageBody +{ + /// + /// 20 + /// iccid,一般开机或者重连第一条0200位置信息上报, + /// 例子报文:f1143839383630343032313032303930393737303032,解析结果为:89860402102090977002 + /// + public class JT808_0x0200_0xf1 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + { + /// + /// + /// + public byte AttachInfoId { get; set; } = JT808_GPS51_Constants.JT808_0x0200_0xf1; + /// + /// + /// + public byte AttachInfoLength { get; set; } + /// + /// ICCID + /// + public string ICCID { get; set; } + + /// + /// + /// + /// + /// + /// + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0xf1 value = new JT808_0x0200_0xf1(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + var iccid = reader.ReadVirtualArray(value.AttachInfoLength); + writer.WriteString($"[{iccid.ToArray().ToHexString()}]ICCID", reader.ReadRemainStringContent()); + } + /// + /// + /// + /// + /// + /// + public override JT808_0x0200_0xf1 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) + { + JT808_0x0200_0xf1 value = new JT808_0x0200_0xf1(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.ICCID = reader.ReadRemainStringContent(); + return value; + } + /// + /// + /// + /// + /// + /// + public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0xf1 value, IJT808Config config) + { + writer.WriteByte(value.AttachInfoId); + writer.Skip(1,out int position); + writer.WriteString(value.ICCID); + var length = writer.GetCurrentPosition() - position - 1; + writer.WriteByteReturn((byte)length, position); + } + } +} diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xf6.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xf6.cs new file mode 100644 index 0000000..52176c5 --- /dev/null +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xf6.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.GPS51.Metadata; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessageBody; +using JT808.Protocol.MessagePack; + +namespace JT808.Protocol.Extensions.GPS51.MessageBody +{ + /// + /// 8 + //// IMEI数据:8字节,第1位为0,后面15位为imei的16进制数据 + /// + public class JT808_0x0200_0xf6 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + { + /// + /// + /// + public byte AttachInfoId { get; set; } = JT808_GPS51_Constants.JT808_0x0200_0xf6; + /// + /// + /// + public byte AttachInfoLength { get; set; } + /// + /// IMEI + /// + public string IMEI { get; set; } + + /// + /// + /// + /// + /// + /// + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0xf6 value = new JT808_0x0200_0xf6(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + var imei = reader.ReadVirtualArray(value.AttachInfoLength); + writer.WriteString($"[{imei.ToArray().ToHexString()}]IMEI", reader.ReadRemainStringContent()); + } + /// + /// + /// + /// + /// + /// + public override JT808_0x0200_0xf6 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) + { + JT808_0x0200_0xf6 value = new JT808_0x0200_0xf6(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.IMEI = reader.ReadRemainStringContent(); + return value; + } + /// + /// + /// + /// + /// + /// + public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0xf6 value, IJT808Config config) + { + writer.WriteByte(value.AttachInfoId); + writer.Skip(1, out int position); + writer.WriteString(value.IMEI); + var length = writer.GetCurrentPosition() - position - 1; + writer.WriteByteReturn((byte)length, position); + } + } +} diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xfa.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xfa.cs new file mode 100644 index 0000000..bc6a65a --- /dev/null +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xfa.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.GPS51.Metadata; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessageBody; +using JT808.Protocol.MessagePack; + +namespace JT808.Protocol.Extensions.GPS51.MessageBody +{ + /// + /// 4 + /// 第0位:震动报警 + /// 第1位:拆除报警 + /// 例子:第0位:震动报警 fa0400000001 第1位:拆除报警 fa0400000002 第2位:进入深度休眠 fa0400000004 第3位:急加速 fa0400000008 + /// 第4位:急减速 fa0400000010 第5位:急转弯 fa0400000020 第6位:acc开报警 fa0400000040 第7位:acc关报警 fa0400000080 + /// 第8位:内部电池电量低fa0400000100 第9位:人为关机 fa0400000200 第10位:低电关机 fa0400000400 第11位:设防(状态) fa0400000800 + /// + public class JT808_0x0200_0xfa : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + { + /// + /// + /// + public byte AttachInfoId { get; set; } = JT808_GPS51_Constants.JT808_0x0200_0xfa; + /// + /// + /// + public byte AttachInfoLength { get; set; } + + public uint Alarm { get; set; } + + /// + /// + /// + /// + /// + /// + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0xfa value = new JT808_0x0200_0xfa(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.Alarm = reader.ReadUInt32(); + writer.WriteStartObject("报警信息"); + var alarm = Convert.ToString(value.Alarm, 2).PadLeft(32, '0').AsSpan(); + writer.WriteString("值", Convert.ToString(value.Alarm, 2).PadLeft(32, '0')); + writer.WriteString("bit0-震动报警", (value.Alarm & 2^0) == 1 ? "有" : "无"); + writer.WriteString("bit1-拆除报警", (value.Alarm & 2 ^ 1) == 1 ? "有" : "无"); + writer.WriteString("bit2-进入深度休眠", (value.Alarm & 2 ^ 2) == 1 ? "有" : "无"); + writer.WriteString("bit3-急加速", (value.Alarm & 2 ^ 3) == 1 ? "有" : "无"); + writer.WriteString("bit4-急减速", (value.Alarm & 2 ^ 4) == 1 ? "有" : "无"); + writer.WriteString("bit5-急转弯", (value.Alarm & 2 ^ 5) == 1 ? "有" : "无"); + writer.WriteString("bit6-acc开报警", (value.Alarm & 2 ^ 6) == 1 ? "有" : "无"); + writer.WriteString("bit7-acc关报警", (value.Alarm & 2 ^ 7) == 1 ? "有" : "无"); + writer.WriteString("bit8-内部电池电量低", (value.Alarm & 2 ^ 8) == 1 ? "有" : "无"); + writer.WriteString("bit9-人为关机", (value.Alarm & 2 ^ 8) == 1 ? "有" : "无"); + writer.WriteString("bit10-低电关机", (value.Alarm & 2 ^ 10) == 1 ? "有" : "无"); + writer.WriteString("bit11-设防(状态)", (value.Alarm & 2 ^ 11) == 1 ? "有" : "无"); + writer.WriteString("bit12~31", "保留"); + writer.WriteEndObject(); + } + /// + /// + /// + /// + /// + /// + public override JT808_0x0200_0xfa Deserialize(ref JT808MessagePackReader reader, IJT808Config config) + { + JT808_0x0200_0xfa value = new JT808_0x0200_0xfa(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.Alarm= reader.ReadUInt32(); + return value; + } + /// + /// + /// + /// + /// + /// + public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0xfa value, IJT808Config config) + { + writer.WriteByte(value.AttachInfoId); + writer.WriteByte(4); + writer.WriteUInt32(value.Alarm); + } + } +} diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xfb.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xfb.cs new file mode 100644 index 0000000..daf665a --- /dev/null +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.GPS51/MessageBody/JT808_0x0200_0xfb.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.GPS51.Metadata; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessageBody; +using JT808.Protocol.MessagePack; + +namespace JT808.Protocol.Extensions.GPS51.MessageBody +{ + /// + /// 4 + /// 电量百分比和外部电压,电压精度0.01V,充电状态0未充电 1充电中,没有的数据传00 + /// 例子:fb045F050701 解析结果:电量百分比5F=95 电压:0507=1287 最终显示为12.87V 01:充电中 + /// + public class JT808_0x0200_0xfb : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + { + /// + /// + /// + public byte AttachInfoId { get; set; } = JT808_GPS51_Constants.JT808_0x0200_0xfb; + /// + /// + /// + public byte AttachInfoLength { get; set; } + /// + /// 电量百分比 + /// + public byte PowerPercent{ get; set; } + /// + /// 电压 + /// + public ushort Power { get; set; } + /// + /// 状态 + /// + public byte Status { get; set; } + /// + /// + /// + /// + /// + /// + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0xfb value = new JT808_0x0200_0xfb(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.PowerPercent = reader.ReadByte(); + writer.WriteNumber($"[{value.PowerPercent.ReadNumber()}]电量百分比", value.PowerPercent); + value.Power = reader.ReadUInt16(); + writer.WriteNumber($"[{value.Power.ReadNumber()}]电压", value.Power); + value.Status = reader.ReadByte(); + writer.WriteString($"[{value.Status.ReadNumber()}]状态", value.Status==0?"未充电":"充电中"); + } + /// + /// + /// + /// + /// + /// + public override JT808_0x0200_0xfb Deserialize(ref JT808MessagePackReader reader, IJT808Config config) + { + JT808_0x0200_0xfb value = new JT808_0x0200_0xfb(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.PowerPercent = reader.ReadByte(); + value.Power = reader.ReadUInt16(); + value.Status = reader.ReadByte(); + return value; + } + /// + /// + /// + /// + /// + /// + public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0xfb value, IJT808Config config) + { + writer.WriteByte(value.AttachInfoId); + writer.WriteByte(4); + writer.WriteByte(value.PowerPercent); + writer.WriteUInt16(value.Power); + writer.WriteByte(value.Status); + } + } +}