Beispiel #1
0
        public TJT809Bodies Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int          offset      = 0;
            TJT809Bodies jT809Bodies = new TJT809Bodies();

            jT809Bodies.VehicleNo       = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 21);
            jT809Bodies.VehicleColor    = (JT809VehicleColorType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809Bodies.SubBusinessType = (JT809SubBusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT809Bodies.DataLength      = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性
            JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809Bodies.SubBusinessType.GetAttribute <JT809BodiesTypeAttribute>();

            if (jT809SubBodiesTypeAttribute == null)
            {
                throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{jT809Bodies.SubBusinessType.ToString()}");
            }
            try
            {
                jT809Bodies.SubBodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), bytes.Slice(offset, (int)jT809Bodies.DataLength), out readSize);
            }
            catch
            {
                throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809Bodies.SubBusinessType.ToString()}");
            }
            readSize = offset;
            return(jT809Bodies);
        }
        public JT809_0x1500_0x1502 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            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);
            if (jT809_0X1500_0X1502.PhotoLen > 0)
            {
                jT809_0X1500_0X1502.Photo = JT809BinaryExtensions.ReadBytesLittle(bytes, ref offset, (int)jT809_0X1500_0X1502.PhotoLen);
            }
            readSize = offset;
            return(jT809_0X1500_0X1502);
        }
        public JT809_0x9500_0x9504 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JT809_0x9500_0x9504 jT809_0X9500_0X9504 = new JT809_0x9500_0x9504();

            jT809_0X9500_0X9504.Command = (JT809CommandType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            switch (jT809_0X9500_0X9504.Command)
            {
            case JT809CommandType.记录仪标准版本:
            case JT809CommandType.当前驾驶人信息:
            case JT809CommandType.记录仪时间:
            case JT809CommandType.记录仪累计行驶里程:
            case JT809CommandType.记录仪脉冲系数:
            case JT809CommandType.车辆信息:
            case JT809CommandType.记录仪状态信号配置信息:
            case JT809CommandType.记录仪唯一性编号:
                break;

            case JT809CommandType.采集记录仪行驶记录:
            case JT809CommandType.采集记录仪位置信息记录:
            case JT809CommandType.采集记录仪事故疑点记录:
            case JT809CommandType.采集记录仪超时驾驶记录:
            case JT809CommandType.采集记录仪驾驶人身份记录:
            case JT809CommandType.采集记录仪外部供电记录:
            case JT809CommandType.采集记录仪参数修改记录:
            case JT809CommandType.采集记录仪速度状态日志:
                jT809_0X9500_0X9504.StartTime = JT809BinaryExtensions.ReadDateTime6Little(bytes, ref offset);
                jT809_0X9500_0X9504.EndTime   = JT809BinaryExtensions.ReadDateTime6Little(bytes, ref offset);
                jT809_0X9500_0X9504.Max       = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset);
                break;
            }
            readSize = offset;
            return(jT809_0X9500_0X9504);
        }
Beispiel #4
0
        public JT809_0x1500_0x1501 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JT809_0x1500_0x1501 jT809_0X1500_0X1501 = new JT809_0x1500_0x1501();

            jT809_0X1500_0X1501.Result = (JT809Enums.JT809_0x1501_Result)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jT809_0X1500_0X1501);
        }
Beispiel #5
0
        public JT809_0x1007 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int          offset       = 0;
            JT809_0x1007 jT809_0X1007 = new JT809_0x1007();

            jT809_0X1007.ErrorCode = (JT809_0x1007_ErrorCode)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jT809_0X1007);
        }
Beispiel #6
0
        public JT809_0x1008 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int          offset       = 0;
            JT809_0x1008 jT809_0X1008 = new JT809_0x1008();

            jT809_0X1008.ReasonCode = (JT809_0x1008_ReasonCode)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jT809_0X1008);
        }
Beispiel #7
0
        public JT809_0x9002 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int          offset       = 0;
            JT809_0x9002 jT809_0X9002 = new JT809_0x9002();

            jT809_0X9002.Result = (JT809_0x9002_Result)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize            = offset;
            return(jT809_0X9002);
        }
Beispiel #8
0
        public JT809_0x9200_0x9205 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JT809_0x9200_0x9205 jT809_0X1200_0x9205 = new JT809_0x9200_0x9205();

            jT809_0X1200_0x9205.ReasonCode = (JT809_0x9205_ReasonCode)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jT809_0X1200_0x9205);
        }
        public JT809_0x9200_0x9207 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JT809_0x9200_0x9207 jT809_0X1200_0x9207 = new JT809_0x9200_0x9207();

            jT809_0X1200_0x9207.Result = (JT809_0x9207_Result)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jT809_0X1200_0x9207);
        }
Beispiel #10
0
        public JT809_0x9500_0x9502 Deserialize(ReadOnlySpan <byte> 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);
        }
Beispiel #11
0
        public JT809_0x1500_0x1503 Deserialize(ReadOnlySpan <byte> 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 = (JT809_0x1503_Result)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jT809_0X1500_0X1503);
        }
Beispiel #12
0
        public JT809_0x1500_0x1504 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JT809_0x1500_0x1504 jT809_0X1500_0X1504 = new JT809_0x1500_0x1504();

            jT809_0X1500_0X1504.CommandType      = (JT809CommandType)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 JT809_0x9500_0x9503 Deserialize(ReadOnlySpan <byte> 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 JT809_0x9300_0x9302 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JT809_0x9300_0x9302 jT809_0X9300_0X9302 = new JT809_0x9300_0x9302();

            jT809_0X9300_0X9302.ObjectType  = (JT809_0x9302_ObjectType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X9300_0X9302.ObjectID    = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 12);
            jT809_0X9300_0X9302.InfoID      = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809_0X9300_0X9302.InfoLength  = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809_0X9300_0X9302.InfoContent = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, (int)jT809_0X9300_0X9302.InfoLength);
            readSize = offset;
            return(jT809_0X9300_0X9302);
        }
Beispiel #15
0
        public JT809_0x9400_0x9403 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JT809_0x9400_0x9403 jT809_0X9400_0X9403 = new JT809_0x9400_0x9403();

            jT809_0X9400_0X9403.WarnSrc     = (JT809WarnSrc)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X9400_0X9403.WarnType    = (JT809WarnType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT809_0X9400_0X9403.WarnTime    = JT809BinaryExtensions.ReadUTCDateTimeLittle(bytes, ref offset);
            jT809_0X9400_0X9403.WarnLength  = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809_0X9400_0X9403.WarnContent = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, (int)jT809_0X9400_0X9403.WarnLength);
            readSize = offset;
            return(jT809_0X9400_0X9403);
        }
Beispiel #16
0
        public JT809_0x1300_0x1301 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JT809_0x1300_0x1301 jT809_0X1200_0X1301 = new JT809_0x1300_0x1301();

            jT809_0X1200_0X1301.ObjectType  = (JT809Enums.JT809_0x1301_ObjectType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X1200_0X1301.ObjectID    = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 12);
            jT809_0X1200_0X1301.InfoID      = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809_0X1200_0X1301.InfoLength  = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809_0X1200_0X1301.InfoContent = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, (int)jT809_0X1200_0X1301.InfoLength);
            readSize = offset;
            return(jT809_0X1200_0X1301);
        }
Beispiel #17
0
        public JT809_0x1400_0x1402 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JT809_0x1400_0x1402 jT809_0X1400_0X1402 = new JT809_0x1400_0x1402();

            jT809_0X1400_0X1402.WarnSrc     = (JT809Enums.JT809WarnSrc)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X1400_0X1402.WarnType    = (JT809Enums.JT809WarnType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT809_0X1400_0X1402.WarnTime    = JT809BinaryExtensions.ReadUTCDateTimeLittle(bytes, ref offset);
            jT809_0X1400_0X1402.InfoID      = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809_0X1400_0X1402.InfoLength  = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809_0X1400_0X1402.InfoContent = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, (int)jT809_0X1400_0X1402.InfoLength);
            readSize = offset;
            return(jT809_0X1400_0X1402);
        }
Beispiel #18
0
        public JT809Header Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int         offset      = 0;
            JT809Header jT809Header = new JT809Header();

            jT809Header.MsgLength       = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809Header.MsgSN           = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809Header.BusinessType    = (JT809BusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT809Header.MsgGNSSCENTERID = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809Header.Version         = new JT809Header_Version(JT809BinaryExtensions.ReadBytesLittle(bytes, ref offset, JT809Header_Version.FixedByteLength));
            jT809Header.EncryptFlag     = (JT809Header_Encrypt)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809Header.EncryptKey      = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            readSize = offset;
            return(jT809Header);
        }
        public JT809_0x9400_0x9401 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JT809_0x9400_0x9401 jT809_0X9400_0X9401 = new JT809_0x9400_0x9401();

            jT809_0X9400_0X9401.WarnSrc            = (JT809WarnSrc)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X9400_0X9401.WarnType           = (JT809WarnType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT809_0X9400_0X9401.WarnTime           = JT809BinaryExtensions.ReadUTCDateTimeLittle(bytes, ref offset);
            jT809_0X9400_0X9401.SupervisionID      = JT809BinaryExtensions.ReadHexStringLittle(bytes, ref offset, 4);
            jT809_0X9400_0X9401.SupervisionEndTime = JT809BinaryExtensions.ReadUTCDateTimeLittle(bytes, ref offset);
            jT809_0X9400_0X9401.SupervisionLevel   = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X9400_0X9401.Supervisor         = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 16);
            jT809_0X9400_0X9401.SupervisorTel      = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 20);
            jT809_0X9400_0X9401.SupervisorEmail    = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 32);
            readSize = offset;
            return(jT809_0X9400_0X9401);
        }
Beispiel #20
0
        public JT809_0x9200_0x9203 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JT809_0x9200_0x9203 jT809_0X1200_0x9203 = new JT809_0x9200_0x9203();

            jT809_0X1200_0x9203.GNSSCount = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X1200_0x9203.GNSS      = new List <JT809_0x9200_0x9202>();
            if (jT809_0X1200_0x9203.GNSSCount > 0)
            {
                int bufReadSize;
                int tempOffset = 0;
                for (int i = 0; i < jT809_0X1200_0x9203.GNSSCount; i++)
                {
                    try
                    {
                        if (i == 0)
                        {
                            tempOffset = offset + 36;
                            JT809_0x9200_0x9202 jT809_0x1200_0x1202 = JT809FormatterExtensions.GetFormatter <JT809_0x9200_0x9202>()
                                                                      .Deserialize(bytes.Slice(offset, 36), out bufReadSize);
                            jT809_0X1200_0x9203.GNSS.Add(jT809_0x1200_0x1202);
                        }
                        else
                        {
                            JT809_0x9200_0x9202 jT809_0x1200_0x9202 = JT809FormatterExtensions.GetFormatter <JT809_0x9200_0x9202>()
                                                                      .Deserialize(bytes.Slice(tempOffset, 36), out bufReadSize);
                            tempOffset += 36;
                            jT809_0X1200_0x9203.GNSS.Add(jT809_0x1200_0x9202);
                        }
                    }
                    catch (Exception)
                    {
                        tempOffset += 36;
                    }
                }
            }
            readSize = jT809_0X1200_0x9203.GNSSCount * 36 + 1;
            return(jT809_0X1200_0x9203);
        }
        public JT809_0x1200_0x1202 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JT809_0x1200_0x1202 jT809_0X1200_0X1202 = new JT809_0x1200_0x1202();

            jT809_0X1200_0X1202.VehiclePosition.Encrypt   = (JT809_VehiclePositionEncrypt)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Day       = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Month     = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Year      = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Hour      = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Minute    = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Second    = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Lon       = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Lat       = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Vec1      = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Vec2      = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Vec3      = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Direction = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Altitude  = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.State     = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT809_0X1200_0X1202.VehiclePosition.Alarm     = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            readSize = offset;
            return(jT809_0X1200_0X1202);
        }
Beispiel #22
0
        public JT809Package Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int          offset       = 0;
            JT809Package jT809Package = new JT809Package();
            // 转义还原——>验证校验码——>解析消息
            // 1. 解码(转义还原)
            ReadOnlySpan <byte> buffer = JT809DeEscape(bytes);
            // 2. 验证校验码
            //  2.1. 获取校验位索引
            int checkIndex = buffer.Length - 3;
            //  2.2. 获取校验码
            int crcCodeOffset = 0;

            jT809Package.CRCCode = JT809BinaryExtensions.ReadUInt16Little(buffer.Slice(checkIndex, 2), ref crcCodeOffset);
            if (!JT809GlobalConfig.Instance.SkipCRCCode)
            {
                //  2.3. 从消息头到校验码前一个字节
                ushort checkCode = buffer.ToCRC16_CCITT(1, checkIndex);
                //  2.4. 验证校验码
                if (jT809Package.CRCCode != checkCode)
                {
                    throw new JT809Exception(JT809ErrorCode.CRC16CheckInvalid, $"{jT809Package.CRCCode.ToString()}!={checkCode.ToString()}");
                }
            }
            jT809Package.BeginFlag = JT809BinaryExtensions.ReadByteLittle(buffer, ref offset);
            // 3.初始化消息头
            try
            {
                jT809Package.Header = JT809FormatterExtensions.GetFormatter <JT809Header>().Deserialize(buffer.Slice(offset, JT809Header.FixedByteLength), out readSize);
            }
            catch (Exception ex)
            {
                throw new JT809Exception(JT809ErrorCode.HeaderParseError, $"offset>{offset.ToString()}", ex);
            }
            offset += readSize;
            // 5.数据体处理
            //  5.1 判断是否有数据体(总长度-固定长度)> 0
            if ((jT809Package.Header.MsgLength - JT809Package.FixedByteLength) > 0)
            {
                //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性
                JT809BodiesTypeAttribute jT809BodiesTypeAttribute = jT809Package.Header.BusinessType.GetAttribute <JT809BodiesTypeAttribute>();
                if (jT809BodiesTypeAttribute != null)
                {
                    try
                    {
                        // 5.2 是否加密
                        switch (jT809Package.Header.EncryptFlag)
                        {
                        case JT809Header_Encrypt.None:
                            //5.3 处理消息体
                            jT809Package.Bodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809BodiesTypeAttribute.JT809BodiesType), buffer.Slice(offset, checkIndex - offset), out readSize);
                            break;

                        case JT809Header_Encrypt.Common:
                            byte[] bodiesData = JT809GlobalConfig.Instance.Encrypt.Decrypt(buffer.Slice(offset, checkIndex - offset).ToArray(), jT809Package.Header.EncryptKey);
                            jT809Package.Bodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809BodiesTypeAttribute.JT809BodiesType), bodiesData, out readSize);
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new JT809Exception(JT809ErrorCode.BodiesParseError, $"offset>{offset.ToString()}", ex);
                    }
                }
            }
            jT809Package.EndFlag = buffer[buffer.Length - 1];
            readSize             = buffer.Length;
            return(jT809Package);
        }