Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public JT808_0x0702 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
        {
            JT808_0x0702 value     = new JT808_0x0702();
            var          firstByte = reader.ReadVirtualByte();

            //因2011第一个字节代表姓名长度 所以该值长度只能为  2,3,4,整个数据长度 62+m+n
            if (firstByte == 0x01)
            {
                value.IC_Card_Status       = (JT808ICCardStatus)reader.ReadByte();
                value.IC_Card_PlugDateTime = reader.ReadDateTime_yyMMddHHmmss();
                if (value.IC_Card_Status == JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班)
                {
                    value.IC_Card_ReadResult = (JT808ICCardReadResult)reader.ReadByte();
                    if (value.IC_Card_ReadResult == JT808ICCardReadResult.IC卡读卡成功)
                    {
                        value.DriverUserNameLength   = reader.ReadByte();
                        value.DriverUserName         = reader.ReadString(value.DriverUserNameLength);
                        value.QualificationCode      = reader.ReadString(20);
                        value.LicenseIssuingLength   = reader.ReadByte();
                        value.LicenseIssuing         = reader.ReadString(value.LicenseIssuingLength);
                        value.CertificateExpiresDate = reader.ReadDateTime_YYYYMMDD();
                        if (reader.Version == JT808Version.JTT2019)
                        {
                            value.DriverIdentityCard = reader.ReadString(20);
                            //兼容808-2019 补充
                            if (reader.ReadCurrentRemainContentLength() > 0)
                            {
                                value.FaceMatchValue = reader.ReadByte();
                                value.UID            = reader.ReadString(20);
                            }
                        }
                    }
                }
            }
            else
            {
                if (firstByte == 0x02 && reader.ReadCurrentRemainContentLength() == 7)
                {
                    //如果字节是0x02且长度只有7,那么该协议就是2013或者2019
                    value.IC_Card_Status       = (JT808ICCardStatus)reader.ReadByte();
                    value.IC_Card_PlugDateTime = reader.ReadDateTime_yyMMddHHmmss();
                }
                else
                {
                    value.DriverUserNameLength = reader.ReadByte();
                    value.DriverUserName       = reader.ReadString(value.DriverUserNameLength);
                    value.DriverIdentityCard   = reader.ReadString(20);
                    value.QualificationCode    = reader.ReadString(40);
                    value.LicenseIssuingLength = reader.ReadByte();
                    value.LicenseIssuing       = reader.ReadString(value.LicenseIssuingLength);
                }
            }
            return(value);
        }
Ejemplo n.º 2
0
        public void ReadDateTimeTest()
        {
            byte[] bytes = "7E2019061923232301231906192323237E".ToHexBytes();
            JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes);

            Assert.Equal(JT808Package.BeginFlag, jT808MessagePackReader.ReadStart());
            Assert.Equal(DateTime.Parse("2019-06-19"), jT808MessagePackReader.ReadDateTime_YYYYMMDD());
            Assert.Equal(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 23, 23, 123), jT808MessagePackReader.ReadDateTime_HHmmssfff());
            Assert.Equal(DateTime.Parse("2019-06-19 23:23:23"), jT808MessagePackReader.ReadDateTime_yyMMddHHmmss());
            Assert.Equal(JT808Package.EndFlag, jT808MessagePackReader.ReadEnd());
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="writer"></param>
        /// <param name="config"></param>
        public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config)
        {
            JT808_0x0702 value     = new JT808_0x0702();
            var          firstByte = reader.ReadVirtualByte();

            //因2011第一个字节代表姓名长度 所以该值长度只能为  2,3,4,整个数据长度 62+m+n
            if (firstByte == 0x01)
            {
                value.IC_Card_Status = (JT808ICCardStatus)reader.ReadByte();
                writer.WriteNumber($"[{((byte)value.IC_Card_Status).ReadNumber()}]状态-{value.IC_Card_Status.ToString()}", (byte)value.IC_Card_Status);
                value.IC_Card_PlugDateTime = reader.ReadDateTime_yyMMddHHmmss();
                writer.WriteString($"[{value.IC_Card_PlugDateTime.ToString("yyMMddHHmmss")}]插拔卡时间", value.IC_Card_PlugDateTime.ToString("yyyy-MM-dd HH:mm:ss"));
                if (value.IC_Card_Status == JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班)
                {
                    value.IC_Card_ReadResult = (JT808ICCardReadResult)reader.ReadByte();
                    writer.WriteNumber($"[{((byte)value.IC_Card_ReadResult).ReadNumber()}]IC卡读取结果-{value.IC_Card_ReadResult.ToString()}", (byte)value.IC_Card_ReadResult);
                    if (value.IC_Card_ReadResult == JT808ICCardReadResult.IC卡读卡成功)
                    {
                        value.DriverUserNameLength = reader.ReadByte();
                        writer.WriteNumber($"[{value.DriverUserNameLength.ReadNumber()}]驾驶员姓名长度", value.DriverUserNameLength);
                        var driverUserNameBuffer = reader.ReadVirtualArray(value.DriverUserNameLength);
                        value.DriverUserName = reader.ReadString(value.DriverUserNameLength);
                        writer.WriteString($"[{driverUserNameBuffer.ToArray().ToHexString()}]驾驶员姓名", value.DriverUserName);
                        var qualificationCodeBuffer = reader.ReadVirtualArray(20);
                        value.QualificationCode = reader.ReadString(20);
                        writer.WriteString($"[{qualificationCodeBuffer.ToArray().ToHexString()}]从业资格证编码", value.QualificationCode);
                        value.LicenseIssuingLength = reader.ReadByte();
                        writer.WriteNumber($"[{value.LicenseIssuingLength.ReadNumber()}]发证机构名称长度", value.LicenseIssuingLength);
                        var licenseIssuingLengtheBuffer = reader.ReadVirtualArray(value.LicenseIssuingLength);
                        value.LicenseIssuing = reader.ReadString(value.LicenseIssuingLength);
                        writer.WriteString($"[{licenseIssuingLengtheBuffer.ToArray().ToHexString()}]发证机构名称", value.LicenseIssuing);
                        value.CertificateExpiresDate = reader.ReadDateTime_YYYYMMDD();
                        writer.WriteString($"[{value.CertificateExpiresDate.ToString("yyMMdd")}]插拔卡时间", value.CertificateExpiresDate.ToString("yyyy-MM-dd"));
                        if (reader.Version == JT808Version.JTT2019)
                        {
                            var driverIdentityCardBuffer = reader.ReadVirtualArray(20);
                            value.DriverIdentityCard = reader.ReadString(20);
                            writer.WriteString($"[{driverIdentityCardBuffer.ToArray().ToHexString()}]驾驶员身份证号", value.DriverIdentityCard);
                            //兼容808-2019 补充
                            if (reader.ReadCurrentRemainContentLength() > 0)
                            {
                                value.FaceMatchValue = reader.ReadByte();
                                writer.WriteNumber($"[{value.FaceMatchValue.Value.ReadNumber()}]人脸匹配度", value.FaceMatchValue.Value);
                                var uidBuffer = reader.ReadVirtualArray(20);
                                value.UID = reader.ReadString(20);
                                writer.WriteString($"[{uidBuffer.ToArray().ToHexString()}]身份证UID", value.UID);
                            }
                        }
                    }
                }
            }
            else
            {
                if (firstByte == 0x02 && reader.ReadCurrentRemainContentLength() == 7)
                {
                    //如果字节是0x02且长度只有7,那么该协议就是2013或者2019
                    value.IC_Card_Status = (JT808ICCardStatus)reader.ReadByte();
                    writer.WriteNumber($"[{((byte)value.IC_Card_Status).ReadNumber()}]状态-{value.IC_Card_Status.ToString()}", (byte)value.IC_Card_Status);
                    value.IC_Card_PlugDateTime = reader.ReadDateTime_yyMMddHHmmss();
                    writer.WriteString($"[{value.IC_Card_PlugDateTime.ToString("yyMMddHHmmss")}]插拔卡时间", value.IC_Card_PlugDateTime.ToString("yyyy-MM-dd HH:mm:ss"));
                }
                else
                {
                    value.DriverUserNameLength = reader.ReadByte();
                    writer.WriteNumber($"[{value.DriverUserNameLength.ReadNumber()}]驾驶员姓名长度", value.DriverUserNameLength);
                    var driverUserNameBuffer = reader.ReadVirtualArray(value.DriverUserNameLength);
                    value.DriverUserName = reader.ReadString(value.DriverUserNameLength);
                    writer.WriteString($"[{driverUserNameBuffer.ToArray().ToHexString()}]驾驶员姓名", value.DriverUserName);
                    var driverIdentityCardBuffer = reader.ReadVirtualArray(20);
                    value.DriverIdentityCard = reader.ReadString(20);
                    writer.WriteString($"[{driverIdentityCardBuffer.ToArray().ToHexString()}]驾驶员身份证号", value.DriverIdentityCard);
                    var qualificationCodeBuffer = reader.ReadVirtualArray(40);
                    value.QualificationCode = reader.ReadString(40);
                    writer.WriteString($"[{qualificationCodeBuffer.ToArray().ToHexString()}]从业资格证编码", value.QualificationCode);
                    value.LicenseIssuingLength = reader.ReadByte();
                    writer.WriteNumber($"[{value.LicenseIssuingLength.ReadNumber()}]发证机构名称长度", value.LicenseIssuingLength);
                    var licenseIssuingBuffer = reader.ReadVirtualArray(value.LicenseIssuingLength);
                    value.LicenseIssuing = reader.ReadString(value.LicenseIssuingLength);
                    writer.WriteString($"[{licenseIssuingBuffer.ToArray().ToHexString()}]发证机构名称", value.LicenseIssuing);
                }
            }
        }