Пример #1
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);
        }
Пример #2
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_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_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);
        }
        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);
        }
Пример #6
0
        public JTNE_0x05_Platform Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x05_Platform jTNE_0X05 = new JTNE_0x05_Platform();

            jTNE_0X05.LoginTime        = JTNEBinaryExtensions.ReadDateTime6Little(bytes, ref offset);
            jTNE_0X05.LoginNum         = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X05.PlatformUserName = JTNEBinaryExtensions.ReadStringLittle(bytes, ref offset, 12);
            jTNE_0X05.PlatformPassword = JTNEBinaryExtensions.ReadStringLittle(bytes, ref offset, 20);
            jTNE_0X05.EncryptMethod    = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jTNE_0X05);
        }
        public JTNE_0x01_Platform Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x01_Platform jTNE_0X01_Platform = new JTNE_0x01_Platform();

            jTNE_0X01_Platform.PDATime       = JTNEBinaryExtensions.ReadDateTime6Little(bytes, ref offset);
            jTNE_0X01_Platform.LoginNum      = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X01_Platform.SIM           = JTNEBinaryExtensions.ReadStringLittle(bytes, ref offset, 20);
            jTNE_0X01_Platform.BatteryCount  = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X01_Platform.BatteryLength = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X01_Platform.BatteryNos    = new List <string>();
            if ((jTNE_0X01_Platform.BatteryCount * jTNE_0X01_Platform.BatteryLength) > 0)
            {
                for (int i = 0; i < jTNE_0X01_Platform.BatteryCount; i++)
                {
                    jTNE_0X01_Platform.BatteryNos.Add(JTNEBinaryExtensions.ReadStringLittle(bytes, ref offset, jTNE_0X01_Platform.BatteryLength));
                }
            }
            readSize = offset;
            return(jTNE_0X01_Platform);
        }