Exemplo n.º 1
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_0x0705 value = new JT808_0x0705();

            value.CanItemCount = reader.ReadUInt16();
            writer.WriteNumber($"[{value.CanItemCount.ReadNumber()}]数据项个数", value.CanItemCount);
            var dateTimeBuffer = reader.ReadVirtualArray(5).ToArray();

            value.FirstCanReceiveTime = reader.ReadDateTime_HHmmssfff();
            writer.WriteString($"[{dateTimeBuffer.ToHexString()}]CAN总线数据接收时间", value.FirstCanReceiveTime.ToString("HH-mm-ss:fff"));
            writer.WriteStartArray("CAN总线数据项");
            for (var i = 0; i < value.CanItemCount; i++)
            {
                writer.WriteStartObject();
                JT808CanProperty jT808CanProperty = new JT808CanProperty();
                jT808CanProperty.CanId = reader.ReadUInt32();
                writer.WriteNumber($"[{ jT808CanProperty.CanId.ReadNumber()}]CAN_ID", jT808CanProperty.CanId);
                jT808CanProperty.CanData = reader.ReadArray(8).ToArray();
                writer.WriteString($"CAN_数据", jT808CanProperty.CanData.ToHexString());
                if (jT808CanProperty.CanData.Length != 8)
                {
                    throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(jT808CanProperty.CanData)}->8");
                }
                writer.WriteEndObject();
            }
            writer.WriteEndArray();
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public JT808_0x0705 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
        {
            JT808_0x0705 value = new JT808_0x0705();

            value.CanItemCount        = reader.ReadUInt16();
            value.FirstCanReceiveTime = reader.ReadDateTime_HHmmssfff();
            value.CanItems            = new List <JT808CanProperty>();
            for (var i = 0; i < value.CanItemCount; i++)
            {
                JT808CanProperty jT808CanProperty = new JT808CanProperty();
                jT808CanProperty.CanId   = reader.ReadUInt32();
                jT808CanProperty.CanData = reader.ReadArray(8).ToArray();
                if (jT808CanProperty.CanData.Length != 8)
                {
                    throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(jT808CanProperty.CanData)}->8");
                }
                value.CanItems.Add(jT808CanProperty);
            }
            return(value);
        }
Exemplo n.º 3
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());
        }