Esempio n. 1
0
 public int Serialize(ref byte[] bytes, int offset, JTNE_0x02_0x08 value)
 {
     offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.TypeCode);
     if (value.BatteryAssemblies != null && value.BatteryAssemblies.Count > 0)
     {
         offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.BatteryAssemblies.Count);
         foreach (var item in value.BatteryAssemblies)
         {
             offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, item.BatteryAssemblyNo);
             offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, item.BatteryAssemblyVoltage);
             offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, item.BatteryAssemblyCurrent);
             offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, item.SingleBatteryCount);
             offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, item.ThisSingleBatteryBeginNo);
             if (item.SingleBatteryVoltages != null && item.SingleBatteryVoltages.Count > 0)
             {
                 offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, (byte)item.SingleBatteryVoltages.Count);
                 foreach (var item1 in item.SingleBatteryVoltages)
                 {
                     offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, item1);
                 }
             }
         }
     }
     return(offset);
 }
 public int Serialize(ref byte[] bytes, int offset, JTNE_0x02_0xA2_Device value)
 {
     offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.TypeCode);
     offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.Length);
     offset += JTNEBinaryExtensions.WriteStringLittle(bytes, offset, value.CompanyName, 20);
     return(offset);
 }
Esempio n. 3
0
 public int Serialize(ref byte[] bytes, int offset, JTNE_0x80 value)
 {
     offset += JTNEBinaryExtensions.WriteDateTime6Little(bytes, offset, value.QueryTime);
     offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.ParamNum);
     offset += JTNEBinaryExtensions.WriteBytesLittle(bytes, offset, value.ParamList);
     return(offset);
 }
Esempio n. 4
0
        public int Serialize(ref byte[] bytes, int offset, JTNEHeaderPackage value)
        {
            // 1.起始符1
            offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.BeginFlag1);
            // 2.起始符2
            offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.BeginFlag2);
            // 3.命令标识
            offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.MsgId);
            // 4.应答标识
            offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.AskId);
            // 5.VIN
            offset += JTNEBinaryExtensions.WriteStringPadRightLittle(bytes, offset, value.VIN, 17);
            // 6.数据加密方式
            offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.EncryptMethod);
            if (value.Bodies != null)
            {
                // 7.数据体
                offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, (ushort)value.Bodies.Length);
                // 8.处理数据体
                offset += JTNEBinaryExtensions.WriteBytesLittle(bytes, offset, value.Bodies);
            }
            else
            {
                offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, 0);
            }
            // 9.校验码
            var bccCode = bytes.ToXor(2, offset);

            offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, bccCode);
            return(offset);
        }
Esempio n. 5
0
        public JTNE_0x02_0x08 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int            offset         = 0;
            JTNE_0x02_0x08 jTNE_0X02_0X08 = new JTNE_0x02_0x08();

            jTNE_0X02_0X08.TypeCode             = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X08.BatteryAssemblyCount = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X08.BatteryAssemblies    = new List <Metadata.BatteryAssembly>();
            for (int i = 0; i < jTNE_0X02_0X08.BatteryAssemblyCount; i++)
            {
                Metadata.BatteryAssembly batteryAssembly = new Metadata.BatteryAssembly();
                batteryAssembly.BatteryAssemblyNo           = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
                batteryAssembly.BatteryAssemblyVoltage      = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
                batteryAssembly.BatteryAssemblyCurrent      = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
                batteryAssembly.SingleBatteryCount          = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
                batteryAssembly.ThisSingleBatteryBeginNo    = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
                batteryAssembly.ThisSingleBatteryBeginCount = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
                batteryAssembly.SingleBatteryVoltages       = new List <ushort>();
                for (var j = 0; j < batteryAssembly.ThisSingleBatteryBeginCount; j++)
                {
                    batteryAssembly.SingleBatteryVoltages.Add(JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset));
                }
                jTNE_0X02_0X08.BatteryAssemblies.Add(batteryAssembly);
            }
            readSize = offset;
            return(jTNE_0X02_0X08);
        }
Esempio n. 6
0
        public JTNE_0x82_0x01 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int            offset         = 0;
            JTNE_0x82_0x01 jTNE_0x82_0x01 = new JTNE_0x82_0x01();
            string         res            = JTNEBinaryExtensions.ReadStringLittle(bytes, ref offset);

            string[] upgradeCommands = res.Split(';');
            jTNE_0x82_0x01.UpgradeCommand = new Metadata.UpgradeCommand();
            jTNE_0x82_0x01.UpgradeCommand.ServerAddress = upgradeCommands[0];
            jTNE_0x82_0x01.UpgradeCommand.DialName      = upgradeCommands[1];
            jTNE_0x82_0x01.UpgradeCommand.DialUserName  = upgradeCommands[2];
            jTNE_0x82_0x01.UpgradeCommand.DialUserPwd   = upgradeCommands[3];
            jTNE_0x82_0x01.UpgradeCommand.ServerUrl     = JTNEGlobalConfigs.Instance.Encoding.GetBytes(upgradeCommands[4]);
            if (ushort.TryParse(upgradeCommands[5], out ushort serverPort))
            {
                jTNE_0x82_0x01.UpgradeCommand.ServerPort = serverPort;
            }
            jTNE_0x82_0x01.UpgradeCommand.ManufacturerID  = upgradeCommands[6];
            jTNE_0x82_0x01.UpgradeCommand.HardwareVersion = upgradeCommands[7];
            jTNE_0x82_0x01.UpgradeCommand.FirmwareVersion = upgradeCommands[8];
            if (ushort.TryParse(upgradeCommands[9], out ushort connectTimeLimit))
            {
                jTNE_0x82_0x01.UpgradeCommand.ConnectTimeLimit = connectTimeLimit;
            }
            readSize = offset;
            return(jTNE_0x82_0x01);
        }
 public JTNE_0x81_0x06 Deserialize(ReadOnlySpan<byte> bytes, out int readSize)
 {
     int offset = 0;
     JTNE_0x81_0x06 jTNE_0x81_0x06 = new JTNE_0x81_0x06();
     jTNE_0x81_0x06.ParamValue = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
     readSize = offset;
     return jTNE_0x81_0x06;
 }
 public int Serialize(ref byte[] bytes, int offset, JTNE_0x02_0x04_Platform value)
 {
     offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.TypeCode);
     offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.EngineStatus);
     offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.Revs);
     offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.FuelRate);
     return(offset);
 }
Esempio n. 9
0
 public int Serialize(ref byte[] bytes, int offset, JTNE_0x82_0x06 value)
 {
     offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.AlarmCommand.AlarmLevel.ToByteValue());
     //if (!string.IsNullOrEmpty(value.AlarmCommand.Alarm)) {
     //    offset += JTNEBinaryExtensions.WriteStringLittle(bytes, offset, value.AlarmCommand.Alarm);
     //}
     return(offset);
 }
 public int Serialize(ref byte[] bytes, int offset, JTNE_0x02_0x05_Device value)
 {
     offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.TypeCode);
     offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.PositioStatus);
     offset += JTNEBinaryExtensions.WriteUInt32Little(bytes, offset, value.Lng);
     offset += JTNEBinaryExtensions.WriteUInt32Little(bytes, offset, value.Lat);
     return(offset);
 }
 public int Serialize(ref byte[] bytes, int offset, JTNE_0x02_0xA1_Platform value)
 {
     offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.TypeCode);
     offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.Length);
     offset += JTNEBinaryExtensions.WriteStringLittle(bytes, offset, value.UserName, 12);
     offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.Age);
     return(offset);
 }
Esempio n. 12
0
        public JTNEHeaderPackage Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;

            // 1.进行固定头校验
            if (bytes[offset] != JTNEPackage.BeginFlag && bytes[offset + 1] == JTNEPackage.BeginFlag)
            {
                throw new JTNEException(JTNEErrorCode.BeginFlagError, $"{bytes[offset]},{bytes[offset + 1]}");
            }
            // 2.进行BCC校验码
            // 校验位 = 报文长度 - 最后一位(校验位)
            if (!JTNEGlobalConfigs.Instance.SkipCRCCode)
            {
                byte bCCCode  = bytes[bytes.Length - 1];
                byte bCCCode2 = bytes.ToXor(2, bytes.Length - 1);
                if (bCCCode != bCCCode2)
                {
                    throw new JTNEException(JTNEErrorCode.BCCCodeError, $"request:{bCCCode}!=calculate:{bCCCode2}");
                }
            }
            JTNEHeaderPackage jTNEPackage = new JTNEHeaderPackage();

            offset += 2;
            // 3.命令标识
            jTNEPackage.MsgId = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            // 4.应答标识
            jTNEPackage.AskId = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            // 5.VIN
            jTNEPackage.VIN = JTNEBinaryExtensions.ReadStringLittle(bytes, ref offset, 17);
            // 6.数据加密方式
            jTNEPackage.EncryptMethod = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            // 7.数据单元长度是数据单元的总字节数
            jTNEPackage.DataUnitLength = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            // 8.数据体
            // 8.1.根据数据加密方式进行解码
            // todo: 8.2.解析出对应数据体
            if (jTNEPackage.DataUnitLength > 0)
            {
                Type jTNEBodiesImplType = JTNEMsgIdFactory.GetBodiesImplTypeByMsgId(jTNEPackage.MsgId);
                if (jTNEBodiesImplType != null)
                {
                    int bodyReadSize = 0;
                    try
                    {
                        jTNEPackage.Bodies = bytes.Slice(offset, jTNEPackage.DataUnitLength).ToArray();
                    }
                    catch (Exception ex)
                    {
                        throw new JTNEException(JTNEErrorCode.BodiesParseError, ex);
                    }
                    offset += bodyReadSize;
                }
            }
            // 9.校验码
            jTNEPackage.BCCCode = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize            = offset;
            return(jTNEPackage);
        }
        public JTNE_0x82_0x00 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int            offset         = 0;
            JTNE_0x82_0x00 jTNE_0x82_0x00 = new JTNE_0x82_0x00();

            jTNE_0x82_0x00.ParamId = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jTNE_0x82_0x00);
        }
Esempio n. 14
0
        public JTNE_0x81_0x02_Device Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x81_0x02_Device jTNE_0x81_0x02 = new JTNE_0x81_0x02_Device();

            jTNE_0x81_0x02.ParamValue = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            readSize = offset;
            return(jTNE_0x81_0x02);
        }
Esempio n. 15
0
 public int Serialize(ref byte[] bytes, int offset, JTNE_0x05_Platform value)
 {
     offset += JTNEBinaryExtensions.WriteDateTime6Little(bytes, offset, value.LoginTime);
     offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.LoginNum);
     offset += JTNEBinaryExtensions.WriteStringLittle(bytes, offset, value.PlatformUserName, 12);
     offset += JTNEBinaryExtensions.WriteStringLittle(bytes, offset, value.PlatformPassword, 20);
     offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.EncryptMethod);
     return(offset);
 }
Esempio n. 16
0
        public JTNE_0x80Reply_0x80 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x80Reply_0x80 jTNE_0x80Reply_0x80 = new JTNE_0x80Reply_0x80();

            jTNE_0x80Reply_0x80.ParamValue = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jTNE_0x80Reply_0x80);
        }
        public JTNE_0x81_0x0C Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int            offset         = 0;
            JTNE_0x81_0x0C jTNE_0x81_0x0C = new JTNE_0x81_0x0C();

            jTNE_0x81_0x0C.ParamValue = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jTNE_0x81_0x0C);
        }
        public JTNE_0x82_0x80_Device Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x82_0x80_Device jTNE_0x82_0x80_Device = new JTNE_0x82_0x80_Device();

            jTNE_0x82_0x80_Device.ParamValue = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jTNE_0x82_0x80_Device);
        }
        public JTNE_0x81_0x08 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int            offset         = 0;
            JTNE_0x81_0x08 jTNE_0x81_0x08 = new JTNE_0x81_0x08();

            jTNE_0x81_0x08.ParamValue = JTNEBinaryExtensions.ReadStringLittle(bytes, ref offset, jTNE_0x81_0x08.ParamLength);
            readSize = offset;
            return(jTNE_0x81_0x08);
        }
        public JTNE_0x81_0x05_Device Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x81_0x05_Device jTNE_0x81_0x05 = new JTNE_0x81_0x05_Device();

            jTNE_0x81_0x05.ParamValue  = JTNEBinaryExtensions.ReadBytesLittle(bytes, ref offset);
            jTNE_0x81_0x05.ParamLength = (byte)bytes.Length;
            readSize = offset;
            return(jTNE_0x81_0x05);
        }
Esempio n. 21
0
        public JTNE_0x80Reply_0x81 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x80Reply_0x81 jTNE_0x80Reply_0x80Reply = new JTNE_0x80Reply_0x81();

            jTNE_0x80Reply_0x80Reply.ParamValue  = JTNEBinaryExtensions.ReadBytesLittle(bytes, ref offset);
            jTNE_0x80Reply_0x80Reply.ParamLength = (byte)bytes.Length;
            readSize = offset;
            return(jTNE_0x80Reply_0x80Reply);
        }
Esempio n. 22
0
 public int Serialize(ref byte[] bytes, int offset, JTNE_0x82 value)
 {
     offset += JTNEBinaryExtensions.WriteDateTime6Little(bytes, offset, value.ControlTime);
     offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.ParamID);
     if (JTNE_0x82_Body.JTNE_0x82Method.TryGetValue(value.ParamID, out Type type))
     {
         offset = JTNEFormatterResolverExtensions.JTNEDynamicSerialize(JTNEFormatterExtensions.GetFormatter(type), ref bytes, offset, value.Parameter);
     }
     return(offset);
 }
Esempio n. 23
0
        public JTNE_0x06 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int       offset    = 0;
            JTNE_0x06 jTNE_0X06 = new JTNE_0x06();

            jTNE_0X06.LogoutTime = JTNEBinaryExtensions.ReadDateTime6Little(bytes, ref offset);
            jTNE_0X06.LogoutNum  = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            readSize             = offset;
            return(jTNE_0X06);
        }
Esempio n. 24
0
        public JTNE_0x82_0x06 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int            offset         = 0;
            JTNE_0x82_0x06 jTNE_0x82_0x06 = new JTNE_0x82_0x06();

            jTNE_0x82_0x06.AlarmCommand            = new Metadata.AlarmCommand();
            jTNE_0x82_0x06.AlarmCommand.AlarmLevel = (JTNEAlarmLevel)JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);

            readSize = offset;
            return(jTNE_0x82_0x06);
        }
Esempio n. 25
0
        public JTNE_0x80 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int       offset    = 0;
            JTNE_0x80 jTNE_0X80 = new JTNE_0x80();

            jTNE_0X80.QueryTime = JTNEBinaryExtensions.ReadDateTime6Little(bytes, ref offset);
            jTNE_0X80.ParamNum  = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X80.ParamList = JTNEBinaryExtensions.ReadBytesLittle(bytes, ref offset, jTNE_0X80.ParamNum);
            readSize            = offset;
            return(jTNE_0X80);
        }
        public JTNE_0x02_0xA2_Device Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x02_0xA2_Device jTNE_0X02_0XA2_Device = new JTNE_0x02_0xA2_Device();

            jTNE_0X02_0XA2_Device.TypeCode    = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0XA2_Device.Length      = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0XA2_Device.CompanyName = JTNEBinaryExtensions.ReadStringLittle(bytes, ref offset, 20);
            readSize = offset;
            return(jTNE_0X02_0XA2_Device);
        }
Esempio n. 27
0
 public int Serialize(ref byte[] bytes, int offset, JTNE_0x81 value)
 {
     offset += JTNEBinaryExtensions.WriteDateTime6Little(bytes, offset, value.OperateTime);
     offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.ParamNum);
     foreach (var item in value.ParamList)
     {
         offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, item.ParamId);
         object obj = JTNEFormatterExtensions.GetFormatter(item.GetType());
         offset = JTNEFormatterResolverExtensions.JTNEDynamicSerialize(obj, ref bytes, offset, item);
     }
     return(offset);
 }
        public JTNE_0x02_0xA1_Platform Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x02_0xA1_Platform jTNE_0X02_0XA1_Platform = new JTNE_0x02_0xA1_Platform();

            jTNE_0X02_0XA1_Platform.TypeCode = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0XA1_Platform.Length   = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0XA1_Platform.UserName = JTNEBinaryExtensions.ReadStringLittle(bytes, ref offset, 12);
            jTNE_0X02_0XA1_Platform.Age      = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            readSize = offset;
            return(jTNE_0X02_0XA1_Platform);
        }
        public JTNE_0x02_0x05_Device Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x02_0x05_Device jTNE_0X02_0X05_Device = new JTNE_0x02_0x05_Device();

            jTNE_0X02_0X05_Device.TypeCode      = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X05_Device.PositioStatus = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X05_Device.Lng           = JTNEBinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jTNE_0X02_0X05_Device.Lat           = JTNEBinaryExtensions.ReadUInt32Little(bytes, ref offset);
            readSize = offset;
            return(jTNE_0X02_0X05_Device);
        }
        public JTNE_0x02_0x04_Platform Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x02_0x04_Platform jTNE_0X02_0X04_Platform = new JTNE_0x02_0x04_Platform();

            jTNE_0X02_0X04_Platform.TypeCode     = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X04_Platform.EngineStatus = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X04_Platform.Revs         = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X04_Platform.FuelRate     = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            readSize = offset;
            return(jTNE_0X02_0X04_Platform);
        }