Beispiel #1
0
 public void Serialize(ref JT809MessagePackWriter writer, JT809_JT1078_0x9800_0x9801 value, IJT809Config config)
 {
     writer.WriteByte(value.ChannelId);
     writer.WriteByte(value.AVitemType);
     writer.WriteArray(value.AuthorizeCode);
     writer.WriteArray(value.GnssData);
 }
 public void Serialize(ref JT809MessagePackWriter writer, JT809_JT1078_0x9A00_0x9A01 value, IJT809Config config)
 {
     writer.WriteByte(value.ChannelId);
     writer.WriteByte(value.AVItemType);
     writer.WriteByte(value.StreamType);
     writer.WriteByte(value.MemType);
     writer.WriteUTCDateTime(value.PlayBackStartTime);
     writer.WriteUTCDateTime(value.PlayBackEndTime);
     writer.WriteArray(value.AuthorizeCode);
     writer.WriteArray(value.GnssData);
 }
Beispiel #3
0
 public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x1202 value, IJT809Config config)
 {
     if (config.Version == JT809Version.JTT2011)
     {
         writer.WriteByte((byte)value.VehiclePosition.Encrypt);
         writer.WriteByte(value.VehiclePosition.Day);
         writer.WriteByte(value.VehiclePosition.Month);
         writer.WriteUInt16(value.VehiclePosition.Year);
         writer.WriteByte(value.VehiclePosition.Hour);
         writer.WriteByte(value.VehiclePosition.Minute);
         writer.WriteByte(value.VehiclePosition.Second);
         writer.WriteUInt32(value.VehiclePosition.Lon);
         writer.WriteUInt32(value.VehiclePosition.Lat);
         writer.WriteUInt16(value.VehiclePosition.Vec1);
         writer.WriteUInt16(value.VehiclePosition.Vec2);
         writer.WriteUInt32(value.VehiclePosition.Vec3);
         writer.WriteUInt16(value.VehiclePosition.Direction);
         writer.WriteUInt16(value.VehiclePosition.Altitude);
         writer.WriteUInt32(value.VehiclePosition.State);
         writer.WriteUInt32(value.VehiclePosition.Alarm);
     }
     else
     {
         writer.WriteByte((byte)value.GNSSData.Encrypt);
         writer.Skip(4, out int position);
         writer.WriteArray(value.GNSSData.GnssData);
         writer.WriteUInt32Return((uint)(writer.GetCurrentPosition() - position - 4), position);
         writer.WriteStringPadRight(value.GNSSData.PlatformId1, 11);
         writer.WriteUInt32(value.GNSSData.Alarm1);
         writer.WriteStringPadRight(value.GNSSData.PlatformId2, 11);
         writer.WriteUInt32(value.GNSSData.Alarm2);
         writer.WriteStringPadRight(value.GNSSData.PlatformId3, 11);
         writer.WriteUInt32(value.GNSSData.Alarm3);
     }
 }
        public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1500_0x1502 value, IJT809Config config)
        {
            writer.WriteByte((byte)value.PhotoRspFlag);
            writer.WriteByte((byte)value.VehiclePosition.Encrypt);
            writer.WriteByte(value.VehiclePosition.Day);
            writer.WriteByte(value.VehiclePosition.Month);
            writer.WriteUInt16(value.VehiclePosition.Year);
            writer.WriteByte(value.VehiclePosition.Hour);
            writer.WriteByte(value.VehiclePosition.Minute);
            writer.WriteByte(value.VehiclePosition.Second);
            writer.WriteUInt32(value.VehiclePosition.Lon);
            writer.WriteUInt32(value.VehiclePosition.Lat);
            writer.WriteUInt16(value.VehiclePosition.Vec1);
            writer.WriteUInt16(value.VehiclePosition.Vec2);
            writer.WriteUInt32(value.VehiclePosition.Vec3);
            writer.WriteUInt16(value.VehiclePosition.Direction);
            writer.WriteUInt16(value.VehiclePosition.Altitude);
            writer.WriteUInt32(value.VehiclePosition.State);
            writer.WriteUInt32(value.VehiclePosition.Alarm);
            writer.WriteByte(value.LensID);
            bool isPhoto = (value.Photo != null && value.Photo.Length > 0);

            writer.WriteUInt32(isPhoto ? (uint)value.Photo.Length : 0);
            writer.WriteByte(value.SizeType);
            writer.WriteByte(value.Type);
            if (isPhoto)
            {
                writer.WriteArray(value.Photo);
            }
        }
Beispiel #5
0
        public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1500_0x1502 value, IJT809Config config)
        {
            writer.WriteByte((byte)value.PhotoRspFlag);
            if (config.Version == JT809Version.JTT2011)
            {
                if (value.VehiclePosition != null)
                {
                    config.GetMessagePackFormatter <JT809VehiclePositionProperties>().Serialize(ref writer, value.VehiclePosition, config);
                }
            }
            else if (config.Version == JT809Version.JTT2019)
            {
                if (value.VehiclePosition_2019 != null)
                {
                    config.GetMessagePackFormatter <JT809VehiclePositionProperties_2019>().Serialize(ref writer, value.VehiclePosition_2019, config);
                }
            }
            writer.WriteByte(value.LensID);
            bool isPhoto = (value.Photo != null && value.Photo.Length > 0);

            writer.WriteUInt32(isPhoto ? (uint)value.Photo.Length : 0);
            writer.WriteByte(value.SizeType.ToByteValue());
            writer.WriteByte(value.Type.ToByteValue());
            if (isPhoto)
            {
                writer.WriteArray(value.Photo);
            }
        }
Beispiel #6
0
 public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1300_0x1303 value, IJT809Config config)
 {
     writer.WriteByte(value.SerialCount);
     foreach (var item in value.SerialList)
     {
         writer.WriteArray(item);
     }
     writer.WriteUTCDateTime(value.Time);
 }
Beispiel #7
0
 public void Serialize(ref JT809MessagePackWriter writer, JT809_JT1078_0x9800_0x9801 value, IJT809Config config)
 {
     writer.WriteByte(value.ChannelId);
     writer.WriteByte(value.AVitemType);
     writer.WriteStringPadRight(value.AuthorizeCode, 64);
     if (value.GnssData != null && value.GnssData.Length > 0)
     {
         writer.WriteArray(value.GnssData);
     }
 }
Beispiel #8
0
 public void Serialize(ref JT809MessagePackWriter writer, JT809Header value, IJT809Config config)
 {
     writer.WriteUInt32(value.MsgLength);
     writer.WriteUInt32(value.MsgSN);
     writer.WriteUInt16(value.BusinessType);
     writer.WriteUInt32(value.MsgGNSSCENTERID);
     writer.WriteArray(value.Version.Buffer);
     writer.WriteByte((byte)value.EncryptFlag);
     writer.WriteUInt32(value.EncryptKey);
 }
 public void Serialize(ref JT809MessagePackWriter writer, JT809_JT1078_0x9900_0x9902 value, IJT809Config config)
 {
     writer.WriteByte(value.ChannelId);
     writer.WriteUTCDateTime(value.StartTime);
     writer.WriteUTCDateTime(value.EndTime);
     writer.WriteUInt64(value.AlarmType);
     writer.WriteByte(value.AVItemType);
     writer.WriteByte(value.StreamType);
     writer.WriteByte(value.MemType);
     writer.WriteStringPadRight(value.AuthorizeCode, 64);
     writer.WriteArray(value.GnssData);
 }
Beispiel #10
0
        public void WriteCRC16Test()
        {
            var bytes = new byte[4096];
            var data  = "5B000000480000008510010133EFB8010000000000270F0133EFB832303138303932303132372E302E302E31000000000000000000000000000000000000000000000003296A915D".ToHexBytes();
            JT809MessagePackWriter jT809MessagePackWriter = new JT809MessagePackWriter(bytes);

            jT809MessagePackWriter.WriteArray(data);
            jT809MessagePackWriter.WriteEncode();
            var result = jT809MessagePackWriter.FlushAndGetEncodingArray();

            Assert.Equal(data, result);
        }
Beispiel #11
0
 public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1500_0x1504 value, IJT809Config config)
 {
     if (config.Version == JT809Version.JTT2019)
     {
         writer.WriteUInt16(value.SourceDataType);
         writer.WriteUInt32(value.SourceMsgSn);
         writer.WriteByte((byte)value.CommandType);
     }
     // 先计算内容长度(汉字为两个字节)
     writer.Skip(4, out int lengthPosition);
     writer.WriteArray(value.TraveldataInfo);
     writer.WriteInt32Return(writer.GetCurrentPosition() - lengthPosition - 4, lengthPosition);
 }
Beispiel #12
0
 public void Serialize(ref JT809MessagePackWriter writer, JT809VehiclePositionProperties_2019 value, IJT809Config config)
 {
     writer.WriteByte((byte)value.Encrypt);
     writer.Skip(4, out int position);
     writer.WriteArray(value.GnssData);
     writer.WriteUInt32Return((uint)(writer.GetCurrentPosition() - position - 4), position);
     writer.WriteStringPadRight(value.PlatformId1, 11);
     writer.WriteUInt32(value.Alarm1);
     writer.WriteStringPadRight(value.PlatformId2, 11);
     writer.WriteUInt32(value.Alarm2);
     writer.WriteStringPadRight(value.PlatformId3, 11);
     writer.WriteUInt32(value.Alarm3);
 }
Beispiel #13
0
        public void Serialize(ref JT809MessagePackWriter writer, JT809Package value, IJT809Config config)
        {
            // -----------开始组包----------
            // 1.起始符
            writer.WriteByte(value.BeginFlag);
            // 2.写入头部数据
            //  2.1.跳过数据长度的写入
            writer.Skip(4, out int lengthPosition);
            //  2.2.报文序列号
            value.Header.MsgSN = value.Header.MsgSN > 0 ? value.Header.MsgSN : config.MsgSNDistributed.Increment();
            writer.WriteUInt32(value.Header.MsgSN);
            //  2.3.业务数据类型
            writer.WriteUInt16(value.Header.BusinessType);
            //  2.4.下级平台接入码
            writer.WriteUInt32(value.Header.MsgGNSSCENTERID);
            //  2.5.版本号
            writer.WriteArray(value.Header.Version.Buffer);
            //  2.6.报文加密
            writer.WriteByte((byte)value.Header.EncryptFlag);
            //  2.7.数据加密密钥
            writer.WriteUInt32(value.Header.EncryptKey);
            // 3.写入数据体
            //  3.1.记录当前开始位置
            int startIndex = writer.GetCurrentPosition();

            //  3.2.写入数据对应数据体
            if (value.Bodies != null)
            {
                JT809MessagePackFormatterResolverExtensions.JT809DynamicSerialize(
                    config.GetMessagePackFormatterByType(value.Bodies.GetType()),
                    ref writer, value.Bodies,
                    config);
            }
            //  3.3.记录当前结束位置
            int endIndex      = writer.GetCurrentPosition();
            int contentLength = endIndex - startIndex;

            if (contentLength > 0)
            {
                // 3.4. 数据加密
                switch (value.Header.EncryptFlag)
                {
                case JT809Header_Encrypt.None:
                    break;

                case JT809Header_Encrypt.Common:
                    // 3.5. 提取数据体并进行加密处理
                    byte[] messageBodyDatEncrypted = config.Encrypt.Encrypt(writer.Extract(startIndex), config.EncryptOptions, value.Header.EncryptKey);
                    int    flagLength = messageBodyDatEncrypted.Length - contentLength;
                    if (flagLength == 0)
                    {
                        // 相等复制
                        writer.CopyTo(messageBodyDatEncrypted, startIndex);
                    }
                    else if (flagLength > 0)
                    {
                        // 扩容
                        writer.Skip(flagLength, out _);
                        writer.CopyTo(messageBodyDatEncrypted, startIndex);
                    }
                    else
                    {
                        // 缩减
                        writer.CopyTo(messageBodyDatEncrypted, startIndex);
                        writer.Shrink(-flagLength);
                    }
                    break;
                }
            }
            // 4.计算内容的总长度(校验码2+终止符1=3)
            writer.WriteInt32Return(writer.GetCurrentPosition() + 3, lengthPosition);
            // 5.校验码
            writer.WriteCRC16();
            // 6.终止符
            writer.WriteByte(value.EndFlag);
            // 7.转义
            writer.WriteEncode();
            // -----------组包完成----------
        }
Beispiel #14
0
 public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1600_0x1602 value, IJT809Config config)
 {
     writer.WriteArray(value.DRVLine);
 }
Beispiel #15
0
 public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9300_0x9303 value, IJT809Config config)
 {
     writer.WriteArray(value.SerialList);
     writer.WriteUTCDateTime(value.Time);
 }
Beispiel #16
0
 public void Serialize(ref JT809MessagePackWriter writer, JT809_JT1078_0x1700_0x1701 value, IJT809Config config)
 {
     writer.WriteArray(value.PlateFormId);
     writer.WriteArray(value.AuthorizeCode1);
     writer.WriteArray(value.AuthorizeCode2);
 }