Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public JT808CarDVRUpPackage Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
        {
            JT808CarDVRUpPackage value = new JT808CarDVRUpPackage();
            int currentPosition        = reader.ReaderCount;

            value.Begin      = reader.ReadUInt16();
            value.CommandId  = reader.ReadByte();
            value.DataLength = reader.ReadUInt16();
            value.KeepFields = reader.ReadByte();
            if (value.DataLength > 0)
            {
                if (config.JT808_CarDVR_Up_Factory.Map.TryGetValue(value.CommandId, out var instance))
                {
                    //4.2.处理消息体
                    dynamic attachImpl = JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(instance, ref reader, config);
                    value.Bodies = attachImpl;
                }
            }
            var(CalculateXorCheckCode, RealXorCheckCode) = reader.ReadCarDVRCheckCode(currentPosition);
            if (!config.SkipCarDVRCRCCode)
            {
                if (RealXorCheckCode != CalculateXorCheckCode)
                {
                    throw new JT808Exception(JT808ErrorCode.CarDVRCheckCodeNotEqual, $"{reader.RealCheckXorCode}!={reader.CalculateCheckXorCode}");
                }
            }
            value.CheckCode = reader.ReadByte();
            return(value);
        }
Beispiel #2
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)
        {
            JT808CarDVRUpPackage value = new JT808CarDVRUpPackage();

            writer.WriteStartObject("行车记录仪上行数据包");
            int currentPosition = reader.ReaderCount;

            value.Begin = reader.ReadUInt16();
            writer.WriteNumber($"[{value.Begin.ReadNumber()}]起始字头", value.Begin);
            value.CommandId = reader.ReadByte();
            //出错标志位
            value.ErrorFlag = value.CommandId == 0xFA || value.CommandId == 0xFB;
            if (!value.ErrorFlag)
            {
                writer.WriteString($"[{value.CommandId.ReadNumber()}]命令字", ((JT808CarDVRCommandID)value.CommandId).ToString());
                value.DataLength = reader.ReadUInt16();
                writer.WriteNumber($"[{value.DataLength.ReadNumber()}]数据块长度", value.DataLength);
            }
            else
            {
                writer.WriteString($"[{value.CommandId.ReadNumber()}]出错标志字", value.CommandId.ToString());
            }
            value.KeepFields = reader.ReadByte();
            writer.WriteNumber($"[{value.KeepFields.ReadNumber()}]保留字", value.KeepFields);
            if (value.DataLength > 0)
            {
                if (config.JT808_CarDVR_Up_Factory.Map.TryGetValue(value.CommandId, out var instance))
                {
                    //4.2.处理消息体
                    writer.WriteStartObject(((JT808CarDVRCommandID)value.CommandId).ToString());
                    instance.Analyze(ref reader, writer, config);
                    writer.WriteEndObject();
                }
            }
            var(CalculateXorCheckCode, RealXorCheckCode) = reader.ReadCarDVRCheckCode(currentPosition);
            value.CheckCode = reader.ReadByte();
            if (RealXorCheckCode != CalculateXorCheckCode)
            {
                writer.WriteString($"[{value.CheckCode.ReadNumber()}]校验位错误", $"{reader.RealCheckXorCode}!={reader.CalculateCheckXorCode}");
            }
            else
            {
                writer.WriteNumber($"[{value.CheckCode.ReadNumber()}]校验位", value.CheckCode);
            }
            writer.WriteEndObject();
        }