diff --git a/README.md b/README.md index 75a347b..e330074 100644 --- a/README.md +++ b/README.md @@ -120,12 +120,20 @@ | 1 | 0x1500 | √ | 主链路车辆监管消息 | | 2 | 0x1501 | √ | 车辆单向监听应答 | | 3 | 0x1502 | √ | 车辆拍照应答 | +| 4 | 0x1503 | √ | 下发车辆报文应答 | +| 5 | 0x1504 | √ | 上报车辆行驶记录应答 | +| 6 | 0x1505 | √ | 车辆应急接入监管平台应答消息 | #### 从链路车辆监管消息 |序号|消息ID|完成情况|消息体名称| |:------:|:------:|:------:|:------:| | 1 | 0x9500 | √ | 从链路车辆监管消息 | +| 2 | 0x9501 | √ | 车辆单向监听请求 | +| 3 | 0x9502 | √ | 车辆拍照请求 | +| 4 | 0x9503 | √ | 下发车辆报文请求 | +| 5 | 0x9504 | √ | 上报车辆行驶记录请求 | +| 6 | 0x9505 | √ | 车辆应急接入监管平台请求消息 | ### 车辆静态信息交换类 diff --git a/doc/GBT-19056.pdf b/doc/GBT-19056.pdf new file mode 100644 index 0000000..12d9b38 Binary files /dev/null and b/doc/GBT-19056.pdf differ diff --git a/src/JT809.Protocol/JT809.Protocol.csproj b/src/JT809.Protocol/JT809.Protocol.csproj index 6467b7f..bc1209b 100644 --- a/src/JT809.Protocol/JT809.Protocol.csproj +++ b/src/JT809.Protocol/JT809.Protocol.csproj @@ -34,12 +34,15 @@ + + + diff --git a/src/JT809.Protocol/JT809Enums/JT809CommandType.cs b/src/JT809.Protocol/JT809Enums/JT809CommandType.cs new file mode 100644 index 0000000..b21ccbf --- /dev/null +++ b/src/JT809.Protocol/JT809Enums/JT809CommandType.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Enums +{ + /// + /// 命令字ID + /// + public enum JT809CommandType:byte + { + 记录仪标准版本=0x00, + 当前驾驶人信息=0x01, + 记录仪时间=0x02, + 记录仪累计行驶里程=0x03, + 记录仪脉冲系数=0x04, + 车辆信息 = 0x05, + 记录仪状态信号配置信息 = 0x06, + 记录仪唯一性编号 = 0x07, + 采集记录仪行驶记录 = 0x08, + 采集记录仪位置信息记录 = 0x09, + 采集记录仪事故疑点记录 = 0x10, + 采集记录仪超时驾驶记录 = 0x11, + 采集记录仪驾驶人身份记录=0x12, + 采集记录仪外部供电记录=0x13, + 采集记录仪参数修改记录 = 0x14, + 采集记录仪速度状态日志 = 0x15, + } +} diff --git a/src/JT809.Protocol/JT809Enums/JT809SubBusinessType.cs b/src/JT809.Protocol/JT809Enums/JT809SubBusinessType.cs index ee1c5ef..5f703e1 100644 --- a/src/JT809.Protocol/JT809Enums/JT809SubBusinessType.cs +++ b/src/JT809.Protocol/JT809Enums/JT809SubBusinessType.cs @@ -236,19 +236,19 @@ namespace JT809.Protocol.JT809Enums ///下发车辆报文应答 /// [Description("下发车辆报文应答")] - //[JT809BodiesType(typeof(JT809_0x1500_0x1503))] + [JT809BodiesType(typeof(JT809_0x1500_0x1503))] UP_CTRL_MSG_TEXT_INFO_ACK = 0x1503, /// ///上报车辆行驶记录应答 /// [Description("上报车辆行驶记录应答")] - //[JT809BodiesType(typeof(JT809_0x1500_0x1504))] + [JT809BodiesType(typeof(JT809_0x1500_0x1504))] UP_CTRL_MSG_TAKE_TRAVEL_ACK = 0x1504, /// ///车辆应急接入监管平台应答消息 /// [Description("车辆应急接入监管平台应答消息")] - //[JT809BodiesType(typeof(JT809_0x1500_0x1505))] + [JT809BodiesType(typeof(JT809_0x1500_0x1505))] UP_CTRL_MSG_EMERGENCY_MONITORING_ACK = 0x1505, #endregion @@ -257,26 +257,31 @@ namespace JT809.Protocol.JT809Enums ///车辆单向监听请求 /// [Description("车辆单向监听请求")] + [JT809BodiesType(typeof(JT809_0x9500_0x9501))] DOWN_CTRL_MSG_MONITOR_VEHICLE_REQ = 0x9501, /// ///车辆拍照请求 /// [Description("车辆拍照请求")] + [JT809BodiesType(typeof(JT809_0x9500_0x9502))] DOWN_CTRL_MSG_TAKE_PHOTO_REQ = 0x9502, /// ///下发车辆报文请求 /// [Description("下发车辆报文请求")] + [JT809BodiesType(typeof(JT809_0x9500_0x9503))] DOWN_CTRL_MSG_TEXT_INFO = 0x9503, /// ///上报车辆行驶记录请求 /// [Description("上报车辆行驶记录请求")] + [JT809BodiesType(typeof(JT809_0x9500_0x9504))] DOWN_CTRL_MSG_TAKE_TRAVEL_REQ = 0x9504, /// ///车辆应急接入监管平台请求消息 /// [Description("车辆应急接入监管平台请求消息")] + [JT809BodiesType(typeof(JT809_0x9500_0x9505))] DOWN_CTRL_MSG_EMERGENCY_MONITORING_REQ = 0x9505, #endregion diff --git a/src/JT809.Protocol/JT809Enums/JT809_0x1503_Result.cs b/src/JT809.Protocol/JT809Enums/JT809_0x1503_Result.cs new file mode 100644 index 0000000..70d5efb --- /dev/null +++ b/src/JT809.Protocol/JT809Enums/JT809_0x1503_Result.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Enums +{ + /// + /// 应答结果 + /// + public enum JT809_0x1503_Result : byte + { + 下发成功 = 0x00, + 下发失败 = 0x01, + } +} diff --git a/src/JT809.Protocol/JT809Enums/JT809_0x1505_Result.cs b/src/JT809.Protocol/JT809Enums/JT809_0x1505_Result.cs new file mode 100644 index 0000000..ec5f390 --- /dev/null +++ b/src/JT809.Protocol/JT809Enums/JT809_0x1505_Result.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Enums +{ + /// + /// 应答结果 + /// + public enum JT809_0x1505_Result : byte + { + 车载终端成功收到该命令 = 0x00, + 无该车辆 = 0x01, + 其它原因失败=0x02 + } +} diff --git a/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs index a5177d3..9f7c4fd 100644 --- a/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs +++ b/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs @@ -181,6 +181,13 @@ namespace JT809.Protocol.JT809Extensions return temp.ToArray(); } + public static byte[] ReadBytesLittle(ReadOnlySpan read, ref int offset) + { + ReadOnlySpan temp = read.Slice(offset); + offset = offset + temp.Length; + return temp.ToArray(); + } + /// /// 数字编码 大端模式、高位在前 /// diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs index 74f18ef..f46db26 100644 --- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs @@ -1,4 +1,6 @@ -using JT809.Protocol.JT809SubMessageBody; +using JT809.Protocol.JT809Enums; +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809SubMessageBody; using System; using System.Buffers; using System.Collections.Generic; @@ -10,12 +12,59 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters { public JT809_0x1500_0x1502 Deserialize(ReadOnlySpan bytes, out int readSize) { - throw new NotImplementedException(); + int offset = 0; + JT809_0x1500_0x1502 jT809_0X1500_0X1502 = new JT809_0x1500_0x1502(); + jT809_0X1500_0X1502.PhotoRspFlag= (JT809_0x1502_PhotoRspFlag)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Encrypt = (JT809_VehiclePositionEncrypt)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Day = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Month = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Year = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Hour = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Minute = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Second = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Lon = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Lat = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Vec1 = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Vec2 = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Vec3 = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Direction = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Altitude = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.State = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); + jT809_0X1500_0X1502.VehiclePosition.Alarm = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); + jT809_0X1500_0X1502.LensID = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X1500_0X1502.PhotoLen = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); + jT809_0X1500_0X1502.SizeType = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X1500_0X1502.Type = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X1500_0X1502.Photo = JT809BinaryExtensions.ReadBytesLittle(bytes, ref offset); + readSize = offset; + return jT809_0X1500_0X1502; } public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x1500_0x1502 value) { - throw new NotImplementedException(); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.PhotoRspFlag); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.VehiclePosition.Encrypt); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Day); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Month); + offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Year); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Hour); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Minute); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Second); + offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Lon); + offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Lat); + offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Vec1); + offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Vec2); + offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Vec3); + offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Direction); + offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Altitude); + offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.State); + offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Alarm); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.LensID); + offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.PhotoLen); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.SizeType); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.Type); + offset += JT809BinaryExtensions.WriteBytesLittle(memoryOwner, offset, value.Photo); + return offset; } } } diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1503Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1503Formatter.cs new file mode 100644 index 0000000..6e47bd3 --- /dev/null +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1503Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters +{ + public class JT809_0x1500_0x1503Formatter : IJT809Formatter + { + public JT809_0x1500_0x1503 Deserialize(ReadOnlySpan bytes, out int readSize) + { + int offset = 0; + JT809_0x1500_0x1503 jT809_0X1500_0X1503 = new JT809_0x1500_0x1503(); + jT809_0X1500_0X1503.MsgID= JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); + jT809_0X1500_0X1503.Result = (JT809Enums.JT809_0x1503_Result)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + readSize = offset; + return jT809_0X1500_0X1503; + } + + public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x1500_0x1503 value) + { + offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.MsgID); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Result); + return offset; + } + } +} diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs new file mode 100644 index 0000000..18f474f --- /dev/null +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs @@ -0,0 +1,34 @@ +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters +{ + public class JT809_0x1500_0x1504Formatter : IJT809Formatter + { + public JT809_0x1500_0x1504 Deserialize(ReadOnlySpan bytes, out int readSize) + { + int offset = 0; + JT809_0x1500_0x1504 jT809_0X1500_0X1504 = new JT809_0x1500_0x1504(); + jT809_0X1500_0X1504.CommandType = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X1500_0X1504.TraveldataLength= JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); + jT809_0X1500_0X1504.TraveldataInfo = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, (int)jT809_0X1500_0X1504.TraveldataLength); + readSize = offset; + return jT809_0X1500_0X1504; + } + + public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x1500_0x1504 value) + { + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.CommandType); + // 先计算内容长度(汉字为两个字节) + offset += 4; + int byteLength = JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.TraveldataInfo); + JT809BinaryExtensions.WriteInt32Little(memoryOwner, offset - 4, byteLength); + offset += byteLength; + return offset; + } + } +} diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1505Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1505Formatter.cs new file mode 100644 index 0000000..4121469 --- /dev/null +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1505Formatter.cs @@ -0,0 +1,27 @@ +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters +{ + public class JT809_0x1500_0x1505Formatter : IJT809Formatter + { + public JT809_0x1500_0x1505 Deserialize(ReadOnlySpan bytes, out int readSize) + { + int offset = 0; + JT809_0x1500_0x1505 jT809_0X1500_0X1505 = new JT809_0x1500_0x1505(); + jT809_0X1500_0X1505.Result = (JT809Enums.JT809_0x1505_Result) JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + readSize = offset; + return jT809_0X1500_0X1505; + } + + public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x1500_0x1505 value) + { + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset,(byte)value.Result); + return offset; + } + } +} diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9501Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9501Formatter.cs new file mode 100644 index 0000000..5253afb --- /dev/null +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9501Formatter.cs @@ -0,0 +1,27 @@ +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters +{ + public class JT809_0x9500_0x9501Formatter : IJT809Formatter + { + public JT809_0x9500_0x9501 Deserialize(ReadOnlySpan bytes, out int readSize) + { + int offset = 0; + JT809_0x9500_0x9501 jT809_0X9500_0X9501 = new JT809_0x9500_0x9501(); + jT809_0X9500_0X9501.MonitorTel = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset,20); + readSize = offset; + return jT809_0X9500_0X9501; + } + + public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x9500_0x9501 value) + { + offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.MonitorTel,20); + return offset; + } + } +} diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9502Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9502Formatter.cs new file mode 100644 index 0000000..355c5ee --- /dev/null +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9502Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters +{ + public class JT809_0x9500_0x9502Formatter : IJT809Formatter + { + public JT809_0x9500_0x9502 Deserialize(ReadOnlySpan bytes, out int readSize) + { + int offset = 0; + JT809_0x9500_0x9502 jT809_0X9500_0X9502 = new JT809_0x9500_0x9502(); + jT809_0X9500_0X9502.LensID = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X9500_0X9502.SizeType = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + readSize = offset; + return jT809_0X9500_0X9502; + } + + public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x9500_0x9502 value) + { + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.LensID); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.SizeType); + return offset; + } + } +} diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9503Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9503Formatter.cs new file mode 100644 index 0000000..3e01be1 --- /dev/null +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9503Formatter.cs @@ -0,0 +1,36 @@ +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters +{ + public class JT809_0x9500_0x9503Formatter : IJT809Formatter + { + public JT809_0x9500_0x9503 Deserialize(ReadOnlySpan bytes, out int readSize) + { + int offset = 0; + JT809_0x9500_0x9503 jT809_0X9500_0X9503 = new JT809_0x9500_0x9503(); + jT809_0X9500_0X9503.MsgSequence = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); + jT809_0X9500_0X9503.MsgPriority = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X9500_0X9503.MsgLength = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); + jT809_0X9500_0X9503.MsgContent = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset,(int)jT809_0X9500_0X9503.MsgLength); + readSize = offset; + return jT809_0X9500_0X9503; + } + + public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x9500_0x9503 value) + { + offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.MsgSequence); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.MsgPriority); + // 先计算内容长度(汉字为两个字节) + offset += 4; + int byteLength = JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.MsgContent); + JT809BinaryExtensions.WriteInt32Little(memoryOwner, offset - 4, byteLength); + offset += byteLength; + return offset; + } + } +} diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs new file mode 100644 index 0000000..4d73307 --- /dev/null +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs @@ -0,0 +1,75 @@ +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters +{ + public class JT809_0x9500_0x9504Formatter : IJT809Formatter + { + public JT809_0x9500_0x9504 Deserialize(ReadOnlySpan bytes, out int readSize) + { + int offset = 0; + JT809_0x9500_0x9504 jT809_0X9500_0X9504 = new JT809_0x9500_0x9504(); + jT809_0X9500_0X9504.Command = (JT809Enums.JT809CommandType) JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + switch (jT809_0X9500_0X9504.Command) + { + case JT809Enums.JT809CommandType.记录仪标准版本: + case JT809Enums.JT809CommandType.当前驾驶人信息: + case JT809Enums.JT809CommandType.记录仪时间: + case JT809Enums.JT809CommandType.记录仪累计行驶里程: + case JT809Enums.JT809CommandType.记录仪脉冲系数: + case JT809Enums.JT809CommandType.车辆信息: + case JT809Enums.JT809CommandType.记录仪状态信号配置信息: + case JT809Enums.JT809CommandType.记录仪唯一性编号: + break; + case JT809Enums.JT809CommandType.采集记录仪行驶记录: + case JT809Enums.JT809CommandType.采集记录仪位置信息记录: + case JT809Enums.JT809CommandType.采集记录仪事故疑点记录: + case JT809Enums.JT809CommandType.采集记录仪超时驾驶记录: + case JT809Enums.JT809CommandType.采集记录仪驾驶人身份记录: + case JT809Enums.JT809CommandType.采集记录仪外部供电记录: + case JT809Enums.JT809CommandType.采集记录仪参数修改记录: + case JT809Enums.JT809CommandType.采集记录仪速度状态日志: + jT809_0X9500_0X9504.StartTime = JT809BinaryExtensions.ReadDateTimeLittle(bytes, ref offset); + jT809_0X9500_0X9504.EndTime = JT809BinaryExtensions.ReadDateTimeLittle(bytes, ref offset); + jT809_0X9500_0X9504.Max = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); + break; + } + readSize = offset; + return jT809_0X9500_0X9504; + } + + public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x9500_0x9504 value) + { + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Command); + switch (value.Command) + { + case JT809Enums.JT809CommandType.记录仪标准版本: + case JT809Enums.JT809CommandType.当前驾驶人信息: + case JT809Enums.JT809CommandType.记录仪时间: + case JT809Enums.JT809CommandType.记录仪累计行驶里程: + case JT809Enums.JT809CommandType.记录仪脉冲系数: + case JT809Enums.JT809CommandType.车辆信息: + case JT809Enums.JT809CommandType.记录仪状态信号配置信息: + case JT809Enums.JT809CommandType.记录仪唯一性编号: + break; + case JT809Enums.JT809CommandType.采集记录仪行驶记录: + case JT809Enums.JT809CommandType.采集记录仪位置信息记录: + case JT809Enums.JT809CommandType.采集记录仪事故疑点记录: + case JT809Enums.JT809CommandType.采集记录仪超时驾驶记录: + case JT809Enums.JT809CommandType.采集记录仪驾驶人身份记录: + case JT809Enums.JT809CommandType.采集记录仪外部供电记录: + case JT809Enums.JT809CommandType.采集记录仪参数修改记录: + case JT809Enums.JT809CommandType.采集记录仪速度状态日志: + offset += JT809BinaryExtensions.WriteDateTime6Little(memoryOwner, offset, value.StartTime); + offset += JT809BinaryExtensions.WriteDateTime6Little(memoryOwner, offset, value.EndTime); + offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.Max); + break; + } + return offset; + } + } +} diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs new file mode 100644 index 0000000..3a0b33f --- /dev/null +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs @@ -0,0 +1,41 @@ +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters +{ + public class JT809_0x9500_0x9505Formatter : IJT809Formatter + { + public JT809_0x9500_0x9505 Deserialize(ReadOnlySpan bytes, out int readSize) + { + int offset = 0; + JT809_0x9500_0x9505 jT809_0X9500_0X9505 = new JT809_0x9500_0x9505(); + jT809_0X9500_0X9505.AuthenticationCode= JT809BinaryExtensions.ReadBCD32(bytes, ref offset,10).ToString(); + jT809_0X9500_0X9505.AccessPointName = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 20); + jT809_0X9500_0X9505.UserName = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset,49); + jT809_0X9500_0X9505.Password = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset,22); + jT809_0X9500_0X9505.ServerIP = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 32); + jT809_0X9500_0X9505.TcpPort = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); + jT809_0X9500_0X9505.UdpPort = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); + jT809_0X9500_0X9505.EndTime = JT809BinaryExtensions.ReadDateTimeLittle(bytes, ref offset); + readSize = offset; + return jT809_0X9500_0X9505; + } + + public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x9500_0x9505 value) + { + offset += JT809BinaryExtensions.WriteBCDLittle(memoryOwner, offset, value.AuthenticationCode,4,10); + offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.AccessPointName,20); + offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.UserName, 49); + offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.Password, 22); + offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.ServerIP, 32); + offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.TcpPort); + offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.UdpPort); + offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.EndTime); + return offset; + } + } +} diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1503.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1503.cs new file mode 100644 index 0000000..38b3fca --- /dev/null +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1503.cs @@ -0,0 +1,28 @@ +using JT809.Protocol.JT809Attributes; +using JT809.Protocol.JT809Enums; +using JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809SubMessageBody +{ + /// + /// 下发车辆报文应答消息 + /// 子业务类型标识:UP_CTRL_MSG_TEXT_INFO_ACK + /// 描述:下级平台应答上级平台下发的报文是否成功到达指定车辆 + /// + [JT809Formatter(typeof(JT809_0x1500_0x1503Formatter))] + public class JT809_0x1500_0x1503:JT809SubBodies + { + /// + /// 消息ID + /// 对应“下发车辆报文请求消息”中的MSG_ID + /// + public uint MsgID { get; set; } + /// + /// 应答结果 + /// + public JT809_0x1503_Result Result { get; set; } + } +} diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1504.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1504.cs new file mode 100644 index 0000000..2cabc13 --- /dev/null +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1504.cs @@ -0,0 +1,30 @@ +using JT809.Protocol.JT809Attributes; +using JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809SubMessageBody +{ + /// + /// 上报车辆行驶记录应答消息 + /// 子业务类型标识:UP_CTRL_MSG_TAKE_T'RAVEL_ACK + /// 描述:下级平台应答上级平台下发的上报车辆行驶记录请求消息,将车辆行驶记录数据上传至上级平台 + /// + [JT809Formatter(typeof(JT809_0x1500_0x1504Formatter))] + public class JT809_0x1500_0x1504:JT809SubBodies + { + /// + /// 命令字 + /// + public byte CommandType { get; set; } + /// + /// 车辆行驶记录数据体长度 + /// + public uint TraveldataLength { get; set; } + /// + /// 车辆行驶记录信息 + /// + public string TraveldataInfo { get; set; } + } +} diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1505.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1505.cs new file mode 100644 index 0000000..3039678 --- /dev/null +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1505.cs @@ -0,0 +1,23 @@ +using JT809.Protocol.JT809Attributes; +using JT809.Protocol.JT809Enums; +using JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809SubMessageBody +{ + /// + /// 车辆应急接入监管平台应答消息 + /// 子业务类型标识: UP_CTRL_MSG_EMERGENCY_MONITORING_ACK + /// 描述:下级平台应答上级平台下发的车辆应急接入监管平台请求消息应答 + /// + [JT809Formatter(typeof(JT809_0x1500_0x1505Formatter))] + public class JT809_0x1500_0x1505:JT809SubBodies + { + /// + /// 应答结果 + /// + public JT809_0x1505_Result Result { get; set; } + } +} diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9501.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9501.cs new file mode 100644 index 0000000..b92ad4f --- /dev/null +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9501.cs @@ -0,0 +1,22 @@ +using JT809.Protocol.JT809Attributes; +using JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809SubMessageBody +{ + /// + /// 车辆单向监听请求消息 + /// 子业务类型标识:DOWN_CTRL_MSG_MONITOR_VEHICLE_REQ + /// 描述:上级平台向下级平台下发车辆单向监听清求消息 + /// + [JT809Formatter(typeof(JT809_0x9500_0x9501Formatter))] + public class JT809_0x9500_0x9501:JT809SubBodies + { + /// + /// 回拨电话号码 + /// + public string MonitorTel { get; set; } + } +} diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9502.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9502.cs new file mode 100644 index 0000000..e6d8813 --- /dev/null +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9502.cs @@ -0,0 +1,26 @@ +using JT809.Protocol.JT809Attributes; +using JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809SubMessageBody +{ + /// + /// 车辆拍照请求消息 + /// 子业务类型标识:DOWN_CTRL_MSG_TAKE_PHOTO_REQ + /// 描述:上级平台向下级平台下发对某指定车辆的拍照请求消息 + /// + [JT809Formatter(typeof(JT809_0x9500_0x9502Formatter))] + public class JT809_0x9500_0x9502:JT809SubBodies + { + /// + /// 镜头ID + /// + public byte LensID { get; set; } + /// + /// 图片大小 + /// + public byte SizeType { get; set; } + } +} diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9503.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9503.cs new file mode 100644 index 0000000..9f58859 --- /dev/null +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9503.cs @@ -0,0 +1,34 @@ +using JT809.Protocol.JT809Attributes; +using JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809SubMessageBody +{ + /// + /// 下发车辆报文请求 + /// 子业务类型标识:DOWN_CTRL_MSG_TEXT_INFO + /// 描述:用于上级平台向下级平台下发报文到某指定车辆 + /// + [JT809Formatter(typeof(JT809_0x9500_0x9503Formatter))] + public class JT809_0x9500_0x9503:JT809SubBodies + { + /// + /// 消息ID序号 + /// + public uint MsgSequence { get; set; } + /// + /// 报文优先级 + /// + public byte MsgPriority { get; set; } + /// + /// 报文信息长度 + /// + public uint MsgLength { get; set; } + /// + /// 报文信息内容 + /// + public string MsgContent { get; set; } + } +} diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9504.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9504.cs new file mode 100644 index 0000000..e557ffb --- /dev/null +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9504.cs @@ -0,0 +1,35 @@ +using JT809.Protocol.JT809Attributes; +using JT809.Protocol.JT809Enums; +using JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809SubMessageBody +{ + /// + /// 上报车辆行驶记录请求消息 + /// 子业务类型标识:DOVJN_CTRL_MSG_TAKE_TRAVEL_REQ + /// 描述:上级平台向下级平台下发上报车辆行驶记录请求消息 + /// + [JT809Formatter(typeof(JT809_0x9500_0x9504Formatter))] + public class JT809_0x9500_0x9504:JT809SubBodies + { + /// + /// 命令字ID + /// + public JT809CommandType Command { get; set; } + /// + /// 开始时间 + /// + public DateTime StartTime { get; set; } + /// + /// 开始时间 + /// + public DateTime EndTime { get; set; } + /// + /// 最大数据数 + /// + public ushort Max { get; set; } + } +} diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9505.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9505.cs new file mode 100644 index 0000000..cb388a5 --- /dev/null +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9500_0x9505.cs @@ -0,0 +1,50 @@ +using JT809.Protocol.JT809Attributes; +using JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809SubMessageBody +{ + /// + /// 车辆应急接入监管平台请求消息 + /// 子业务类型标识:UP_CTRL_MSG_EMERGENCY_MONITORING_REQ + /// 描述:发生应急情况时,政府监管平台需要及时监控该车辆时,就向该车辆归属的下级平台发送该命令 + /// + [JT809Formatter(typeof(JT809_0x9500_0x9505Formatter))] + public class JT809_0x9500_0x9505:JT809SubBodies + { + /// + /// 监管平台下发的鉴权码 + /// + public string AuthenticationCode { get; set; } + /// + /// 拨号点名称 + /// + public string AccessPointName { get; set; } + /// + /// 拨号用户名 + /// + public string UserName { get; set; } + /// + /// 拨号密码 + /// + public string Password { get; set; } + /// + /// 地址 + /// + public string ServerIP { get; set; } + /// + /// 服务器TCP端口 + /// + public ushort TcpPort { get; set; } + /// + /// 服务器UDP端口 + /// + public ushort UdpPort { get; set; } + /// + /// 结束时间 + /// + public DateTime EndTime { get; set; } + } +}