コード例 #1
0
        public JT808_0x0702 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int          offset       = 0;
            JT808_0x0702 jT808_0X0702 = new JT808_0x0702();

            jT808_0X0702.IC_Card_Status       = (JT808ICCardStatus)JT808BinaryExtensions.ReadByteLittle(bytes, ref offset);
            jT808_0X0702.IC_Card_PlugDateTime = JT808BinaryExtensions.ReadDateTimeLittle(bytes, ref offset);
            if (jT808_0X0702.IC_Card_Status == JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班)
            {
                jT808_0X0702.IC_Card_ReadResult = (JT808ICCardReadResult)JT808BinaryExtensions.ReadByteLittle(bytes, ref offset);
                if (jT808_0X0702.IC_Card_ReadResult == JT808ICCardReadResult.IC卡读卡成功)
                {
                    jT808_0X0702.DriverUserNameLength   = JT808BinaryExtensions.ReadByteLittle(bytes, ref offset);
                    jT808_0X0702.DriverUserName         = JT808BinaryExtensions.ReadStringLittle(bytes, ref offset, jT808_0X0702.DriverUserNameLength);
                    jT808_0X0702.QualificationCode      = JT808BinaryExtensions.ReadStringLittle(bytes, ref offset, 20);
                    jT808_0X0702.LicenseIssuingLength   = JT808BinaryExtensions.ReadByteLittle(bytes, ref offset);
                    jT808_0X0702.LicenseIssuing         = JT808BinaryExtensions.ReadStringLittle(bytes, ref offset, jT808_0X0702.LicenseIssuingLength);
                    jT808_0X0702.CertificateExpiresDate = JT808BinaryExtensions.ReadDateLittle(bytes, ref offset);
                }
            }
            readSize = offset;
            return(jT808_0X0702);
        }
コード例 #2
0
        public JT808_0x0200 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int          offset       = 0;
            JT808_0x0200 jT808_0X0200 = new JT808_0x0200();

            jT808_0X0200.AlarmFlag  = JT808BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT808_0X0200.StatusFlag = JT808BinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jT808_0X0200.Lat        = JT808BinaryExtensions.ReadInt32Little(bytes, ref offset);
            jT808_0X0200.Lng        = JT808BinaryExtensions.ReadInt32Little(bytes, ref offset);
            JT808StatusProperty jT808StatusProperty = new JT808StatusProperty(Convert.ToString(jT808_0X0200.StatusFlag, 2).PadLeft(32, '0'));

            if (jT808StatusProperty.Bit28 == '1')//西经
            {
                jT808_0X0200.Lng = -jT808_0X0200.Lng;
            }
            if (jT808StatusProperty.Bit29 == '1')//南纬
            {
                jT808_0X0200.Lat = -jT808_0X0200.Lat;
            }
            jT808_0X0200.Altitude  = JT808BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT808_0X0200.Speed     = JT808BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT808_0X0200.Direction = JT808BinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jT808_0X0200.GPSTime   = JT808BinaryExtensions.ReadDateTimeLittle(bytes, ref offset);
            // 位置附加信息
            jT808_0X0200.JT808LocationAttachData = new Dictionary <byte, JT808LocationAttachBase>();
            if (bytes.Length > 28)
            {
                int attachOffset = 0;
                ReadOnlySpan <byte> locationAttachMemory = bytes;
                ReadOnlySpan <byte> locationAttachSpan   = locationAttachMemory.Slice(28);
                while (locationAttachSpan.Length > attachOffset)
                {
                    int attachId  = 1;
                    int attachLen = 1;
                    try
                    {
                        Type jT808LocationAttachType;
                        if (JT808LocationAttachBase.JT808LocationAttachMethod.TryGetValue(locationAttachSpan[attachOffset], out jT808LocationAttachType))
                        {
                            int attachContentLen             = locationAttachSpan[attachOffset + 1];
                            int locationAttachTotalLen       = attachId + attachLen + attachContentLen;
                            ReadOnlySpan <byte> attachBuffer = locationAttachSpan.Slice(attachOffset, locationAttachTotalLen);
                            object  attachImplObj            = JT808FormatterExtensions.GetFormatter(jT808LocationAttachType);
                            dynamic attachImpl = JT808FormatterResolverExtensions.JT808DynamicDeserialize(attachImplObj, attachBuffer, out readSize);
                            attachOffset = attachOffset + locationAttachTotalLen;
                            jT808_0X0200.JT808LocationAttachData.Add(attachImpl.AttachInfoId, attachImpl);
                        }
                        else
                        {
                            int attachContentLen       = locationAttachSpan[attachOffset + 1];
                            int locationAttachTotalLen = attachId + attachLen + attachContentLen;
                            attachOffset = attachOffset + locationAttachTotalLen;
                        }
                    }
                    catch (Exception ex)
                    {
                        int attachContentLen       = locationAttachSpan[attachOffset + 1];
                        int locationAttachTotalLen = attachId + attachLen + attachContentLen;
                        attachOffset = attachOffset + locationAttachTotalLen;
                    }
                }
                offset = offset + attachOffset;
            }
            readSize = offset;
            return(jT808_0X0200);
        }