Exemple #1
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);
        }
Exemple #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_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);
        }
        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_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);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #9
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);
        }
        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);
        }
        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);
        }
Exemple #13
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_0x82 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int       offset    = 0;
            JTNE_0x82 jTNE_0x82 = new JTNE_0x82();

            jTNE_0x82.ControlTime = JTNEBinaryExtensions.ReadDateTime6Little(bytes, ref offset);
            jTNE_0x82.ParamID     = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);//参数ID

            if (JTNE_0x82_Body.JTNE_0x82Method.TryGetValue(jTNE_0x82.ParamID, out Type type))
            {
                int readSubBodySize = 0;
                jTNE_0x82.Parameter = JTNEFormatterResolverExtensions.JTNEDynamicDeserialize(JTNEFormatterExtensions.GetFormatter(type), bytes.Slice(offset), out readSubBodySize);
                offset = offset + readSubBodySize;
            }
            readSize = offset;
            return(jTNE_0x82);
        }
Exemple #15
0
        public JTNE_0x02_0x09_Device Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x02_0x09_Device jTNE_0X02_0X09 = new JTNE_0x02_0x09_Device();

            jTNE_0X02_0X09.TypeCode = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X09.BatteryTemperatureCount = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X09.BatteryTemperatures     = new List <Metadata.BatteryTemperature>();
            for (int i = 0; i < jTNE_0X02_0X09.BatteryTemperatureCount; i++)
            {
                Metadata.BatteryTemperature batteryTemperature = new Metadata.BatteryTemperature();
                batteryTemperature.BatteryAssemblyNo     = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
                batteryTemperature.TemperatureProbeCount = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
                batteryTemperature.Temperatures          = JTNEBinaryExtensions.ReadBytesLittle(bytes, ref offset, batteryTemperature.TemperatureProbeCount);
                jTNE_0X02_0X09.BatteryTemperatures.Add(batteryTemperature);
            }
            readSize = offset;
            return(jTNE_0X02_0X09);
        }
        public JTNE_0x02_0x01_Platform Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x02_0x01_Platform jTNE_0X02_0X01_Platform = new JTNE_0x02_0x01_Platform();

            jTNE_0X02_0X01_Platform.TypeCode      = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01_Platform.CarStatus     = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01_Platform.ChargeStatus  = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01_Platform.OperationMode = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01_Platform.Speed         = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X01_Platform.TotalDis      = JTNEBinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jTNE_0X02_0X01_Platform.TotalVoltage  = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X01_Platform.TotalTemp     = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X01_Platform.SOC           = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01_Platform.DCStatus      = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01_Platform.Stall         = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01_Platform.Resistance    = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            readSize = offset;
            return(jTNE_0X02_0X01_Platform);
        }
Exemple #17
0
        public JTNE_0x81 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int       offset    = 0;
            JTNE_0x81 jTNE_0X81 = new JTNE_0x81();

            jTNE_0X81.OperateTime = JTNEBinaryExtensions.ReadDateTime6Little(bytes, ref offset);
            jTNE_0X81.ParamNum    = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            for (int i = 0; i < jTNE_0X81.ParamNum; i++)
            {
                var paramId         = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);//参数ID
                int readSubBodySize = 0;
                if (JTNE_0x81_Body.JTNE_0x81Method.TryGetValue(paramId, out Type type))
                {
                    ReadOnlySpan <byte> readOnlySpan = new ReadOnlySpan <byte>();
                    if (JTNE_0x81_Body.JTNE_0x81LengthOfADependOnValueOfB.TryGetValue(paramId, out byte dependOnParamId))
                    {
                        var length     = jTNE_0X81.ParamList.FirstOrDefault(m => m.ParamId == dependOnParamId).ParamLength;
                        int tempOffset = 0;
                        int lengthVal  = JTNEBinaryExtensions.ReadByteLittle(bytes.Slice(offset - length - 1, length), ref tempOffset);
                        readOnlySpan = bytes.Slice(offset, lengthVal);
                    }
                    else
                    {
                        readOnlySpan = bytes.Slice(offset);
                    }
                    if (jTNE_0X81.ParamList != null)
                    {
                        jTNE_0X81.ParamList.Add(JTNEFormatterResolverExtensions.JTNEDynamicDeserialize(JTNEFormatterExtensions.GetFormatter(type), readOnlySpan, out readSubBodySize));
                    }
                    else
                    {
                        jTNE_0X81.ParamList = new List <JTNE_0x81_Body> {
                            JTNEFormatterResolverExtensions.JTNEDynamicDeserialize(JTNEFormatterExtensions.GetFormatter(type), readOnlySpan, out readSubBodySize)
                        };
                    }
                }
                offset = offset + readSubBodySize;
            }
            readSize = offset;
            return(jTNE_0X81);
        }
        public JTNE_0x02_0x03 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int            offset         = 0;
            JTNE_0x02_0x03 jTNE_0X02_0X03 = new JTNE_0x02_0x03();

            jTNE_0X02_0X03.TypeCode                          = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X03.FuelBatteryVoltage                = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X03.FuelBatteryCurrent                = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X03.FuelConsumptionRate               = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X03.TemperatureProbeCount             = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X03.Temperatures                      = JTNEBinaryExtensions.ReadBytesLittle(bytes, ref offset, jTNE_0X02_0X03.TemperatureProbeCount);
            jTNE_0X02_0X03.HydrogenSystemMaxTemp             = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X03.HydrogenSystemMaxTempNo           = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X03.HydrogenSystemMaxConcentrations   = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X03.HydrogenSystemMaxConcentrationsNo = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X03.HydrogenSystemMaxPressure         = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X03.HydrogenSystemMaxPressureNo       = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X03.DCStatus                          = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jTNE_0X02_0X03);
        }
Exemple #19
0
        public JTNE_0x02_0x06_Device Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int offset = 0;
            JTNE_0x02_0x06_Device jTNE_0X02_0X06_Device = new JTNE_0x02_0x06_Device();

            jTNE_0X02_0X06_Device.TypeCode = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X06_Device.MaxVoltageBatteryAssemblyNo  = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X06_Device.MaxVoltageSingleBatteryNo    = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X06_Device.MaxVoltageSingleBatteryValue = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X06_Device.MinVoltageBatteryAssemblyNo  = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X06_Device.MinVoltageSingleBatteryNo    = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X06_Device.MinVoltageSingleBatteryValue = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X06_Device.MaxTempProbeBatteryNo        = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X06_Device.MaxTempBatteryAssemblyNo     = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X06_Device.MaxTempProbeBatteryValue     = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X06_Device.MinTempProbeBatteryNo        = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X06_Device.MinTempBatteryAssemblyNo     = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X06_Device.MinTempProbeBatteryValue     = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jTNE_0X02_0X06_Device);
        }
        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);
        }
Exemple #21
0
        public JTNE_0x02_0x07 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int            offset         = 0;
            JTNE_0x02_0x07 jTNE_0X02_0X07 = new JTNE_0x02_0x07();

            jTNE_0X02_0X07.TypeCode         = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X07.AlarmLevel       = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X07.AlarmBatteryFlag = JTNEBinaryExtensions.ReadUInt32Little(bytes, ref offset);

            jTNE_0X02_0X07.AlarmBatteryOtherCount = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X07.AlarmBatteryOthers     = new List <uint>();
            for (int i = 0; i < jTNE_0X02_0X07.AlarmBatteryOtherCount; i++)
            {
                jTNE_0X02_0X07.AlarmBatteryOthers.Add(JTNEBinaryExtensions.ReadUInt32Little(bytes, ref offset));
            }

            jTNE_0X02_0X07.AlarmElCount = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X07.AlarmEls     = new List <uint>();
            for (int i = 0; i < jTNE_0X02_0X07.AlarmElCount; i++)
            {
                jTNE_0X02_0X07.AlarmEls.Add(JTNEBinaryExtensions.ReadUInt32Little(bytes, ref offset));
            }

            jTNE_0X02_0X07.AlarmEngineCount = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X07.AlarmEngines     = new List <uint>();
            for (int i = 0; i < jTNE_0X02_0X07.AlarmEngineCount; i++)
            {
                jTNE_0X02_0X07.AlarmEngines.Add(JTNEBinaryExtensions.ReadUInt32Little(bytes, ref offset));
            }

            jTNE_0X02_0X07.AlarmOtherCount = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X07.AlarmOthers     = new List <uint>();
            for (int i = 0; i < jTNE_0X02_0X07.AlarmOtherCount; i++)
            {
                jTNE_0X02_0X07.AlarmOthers.Add(JTNEBinaryExtensions.ReadUInt32Little(bytes, ref offset));
            }

            readSize = offset;
            return(jTNE_0X02_0X07);
        }
        public JTNE_0x02_0x01 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int            offset         = 0;
            JTNE_0x02_0x01 jTNE_0X02_0X01 = new JTNE_0x02_0x01();

            jTNE_0X02_0X01.TypeCode      = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01.CarStatus     = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01.ChargeStatus  = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01.OperationMode = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01.Speed         = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X01.TotalDis      = JTNEBinaryExtensions.ReadUInt32Little(bytes, ref offset);
            jTNE_0X02_0X01.TotalVoltage  = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X01.TotalTemp     = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X01.SOC           = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01.DCStatus      = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01.Stall         = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01.Resistance    = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
            jTNE_0X02_0X01.Accelerator   = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X01.Brakes        = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            readSize = offset;
            return(jTNE_0X02_0X01);
        }
        public JTNE_0x02 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int       offset = 0, bodyReadSize = 0;
            JTNE_0x02 jTNE_0X02 = new JTNE_0x02();

            jTNE_0X02.Values       = new Dictionary <byte, JTNE_0x02_Body>();
            jTNE_0X02.CusotmValues = new Dictionary <byte, byte[]>();
            while (offset < bytes.Length)
            {
                byte typeCode = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
                if (JTNE_0x02_Body.TypeCodes.TryGetValue(typeCode, out Type jTNE_0x02_BodyImpl))
                {
                    var bodyImplFormatter = JTNEFormatterExtensions.GetFormatter(jTNE_0x02_BodyImpl);
                    //从类型编码开始取 offset - 1
                    var bodyData = JTNEFormatterResolverExtensions.JTNEDynamicDeserialize(bodyImplFormatter, bytes.Slice(offset - 1), out bodyReadSize);
                    jTNE_0X02.Values.Add(typeCode, bodyData);
                    offset += bodyReadSize - 1;
                }
                else if (JTNE_0x02_CustomBody.CustomTypeCodes.TryGetValue(typeCode, out Type jTNE_0x02_CustomBodyImpl))
                {
                    int length = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
                    //从类型编码开始取 offset - 1 - 2
                    //1:类型编码
                    //2:自定义数据长度
                    byte[] customBodyData = bytes.Slice(offset - 1 - 2, length + 1 + 2).ToArray();
                    jTNE_0X02.CusotmValues.Add(typeCode, customBodyData);
                    offset += customBodyData.Length - 1 - 2;
                }
                else
                {
                    offset += bodyReadSize;
                    break;
                }
            }
            readSize = offset;
            return(jTNE_0X02);
        }
        public JTNE_0x02_0x02 Deserialize(ReadOnlySpan <byte> bytes, out int readSize)
        {
            int            offset         = 0;
            JTNE_0x02_0x02 jTNE_0X02_0X02 = new JTNE_0x02_0x02();

            jTNE_0X02_0X02.TypeCode        = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X02.ElectricalCount = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
            jTNE_0X02_0X02.Electricals     = new List <Metadata.Electrical>();
            for (var i = 0; i < jTNE_0X02_0X02.ElectricalCount; i++)
            {
                Metadata.Electrical electrical = new Metadata.Electrical();
                electrical.ElNo          = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
                electrical.ElStatus      = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
                electrical.ElControlTemp = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
                electrical.ElSpeed       = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
                electrical.ElTorque      = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
                electrical.ElTemp        = JTNEBinaryExtensions.ReadByteLittle(bytes, ref offset);
                electrical.ElVoltage     = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
                electrical.ElCurrent     = JTNEBinaryExtensions.ReadUInt16Little(bytes, ref offset);
                jTNE_0X02_0X02.Electricals.Add(electrical);
            }
            readSize = offset;
            return(jTNE_0X02_0X02);
        }