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); }
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); }
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_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); }
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); }
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); }
public int Serialize(ref byte[] bytes, int offset, JTNE_0x01_Platform value) { offset += JTNEBinaryExtensions.WriteDateTime6Little(bytes, offset, value.PDATime); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.LoginNum); offset += JTNEBinaryExtensions.WriteStringLittle(bytes, offset, value.SIM, 20); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.BatteryNos.Count); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.BatteryLength); foreach (var item in value.BatteryNos) { offset += JTNEBinaryExtensions.WriteStringLittle(bytes, offset, item, value.BatteryLength); } return(offset); }
public int Serialize(ref byte[] bytes, int offset, JTNE_0x02_0x01_Platform value) { offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.TypeCode); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.CarStatus); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.ChargeStatus); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.OperationMode); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.Speed); offset += JTNEBinaryExtensions.WriteUInt32Little(bytes, offset, value.TotalDis); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.TotalVoltage); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.TotalTemp); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.SOC); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.DCStatus); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.Stall); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.Resistance); return(offset); }
public int Serialize(ref byte[] bytes, int offset, JTNE_0x02_0x03 value) { offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.TypeCode); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.FuelBatteryVoltage); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.FuelBatteryCurrent); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.FuelConsumptionRate); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, (ushort)value.Temperatures.Length); offset += JTNEBinaryExtensions.WriteBytesLittle(bytes, offset, value.Temperatures); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.HydrogenSystemMaxTemp); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.HydrogenSystemMaxTempNo); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.HydrogenSystemMaxConcentrations); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.HydrogenSystemMaxConcentrationsNo); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.HydrogenSystemMaxPressure); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.HydrogenSystemMaxPressureNo); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.DCStatus); return(offset); }
public int Serialize(ref byte[] bytes, int offset, JTNE_0x02_0x06_Device value) { offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.TypeCode); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.MaxVoltageBatteryAssemblyNo); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.MaxVoltageSingleBatteryNo); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.MaxVoltageSingleBatteryValue); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.MinVoltageBatteryAssemblyNo); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.MinVoltageSingleBatteryNo); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.MinVoltageSingleBatteryValue); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.MaxTempProbeBatteryNo); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.MaxTempBatteryAssemblyNo); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.MaxTempProbeBatteryValue); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.MinTempProbeBatteryNo); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.MinTempBatteryAssemblyNo); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.MinTempProbeBatteryValue); return(offset); }
public int Serialize(ref byte[] bytes, int offset, JTNE_0x02_0x09_Device value) { offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.TypeCode); if (value.BatteryTemperatures != null && value.BatteryTemperatures.Count > 0) { offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.BatteryTemperatures.Count); foreach (var item in value.BatteryTemperatures) { offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, item.BatteryAssemblyNo); if (item.Temperatures != null && item.Temperatures.Length > 0) { offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, (byte)item.Temperatures.Length); offset += JTNEBinaryExtensions.WriteBytesLittle(bytes, offset, item.Temperatures); } } } return(offset); }
public int Serialize(ref byte[] bytes, int offset, JTNE_0x02_0x02 value) { offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, value.TypeCode); if (value.Electricals != null && value.Electricals.Count > 0) { offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.Electricals.Count); foreach (var item in value.Electricals) { offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, item.ElNo); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, item.ElStatus); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, item.ElControlTemp); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, item.ElSpeed); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, item.ElTorque); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, item.ElTemp); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, item.ElVoltage); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, item.ElCurrent); } } return(offset); }
public int Serialize(ref byte[] bytes, int offset, JTNE_0x81_0x0F value) { offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.ParamValue); return(offset); }
public int Serialize(ref byte[] bytes, int offset, JTNE_0x06 value) { offset += JTNEBinaryExtensions.WriteDateTime6Little(bytes, offset, value.LogoutTime); offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, value.LogoutNum); return(offset); }
public int Serialize(ref byte[] bytes, int offset, JTNEPackage 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); // 7.记录当前偏移量 int tmpOffset = offset; // 8.数据体 Type jTNEBodiesImplType = JTNEMsgIdFactory.GetBodiesImplTypeByMsgId(value.MsgId); int messageBodyOffset = 0; if (jTNEBodiesImplType != null) { if (value.Bodies != null) { // 8.1.处理数据体 // 8.2.判断是否有加密 messageBodyOffset = JTNEFormatterResolverExtensions.JTNEDynamicSerialize( JTNEFormatterExtensions.GetFormatter(jTNEBodiesImplType), ref bytes, offset + FixedDataBodyLength, value.Bodies); if (value.EncryptMethod == 0x01) { // 9.通过tmpOffset反写数据单元长度 JTNEBinaryExtensions.WriteUInt16Little(bytes, tmpOffset, (ushort)(messageBodyOffset - offset - FixedDataBodyLength)); offset = messageBodyOffset; } else { if (JTNEGlobalConfigs.Instance.DataBodiesEncrypt != null) { // 8.1.先进行分割数据体 var bodiesData = bytes.AsSpan(tmpOffset + FixedDataBodyLength, messageBodyOffset - offset - FixedDataBodyLength).ToArray(); // 8.2.将数据体进行加密 var data = JTNEGlobalConfigs.Instance.DataBodiesEncrypt(value.EncryptMethod) .Encrypt(bodiesData); // 9.通过tmpOffset反写加密后数据单元长度 JTNEBinaryExtensions.WriteUInt16Little(bytes, tmpOffset, (ushort)data.Length); // 8.3.写入加密后的数据体 offset += FixedDataBodyLength; offset += JTNEBinaryExtensions.WriteBytesLittle(bytes, offset, data); } } } else { // 9.数据单元长度 offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, 0); } } else { // 9.数据单元长度 offset += JTNEBinaryExtensions.WriteUInt16Little(bytes, offset, 0); } // 10.校验码 var bccCode = bytes.ToXor(2, offset); offset += JTNEBinaryExtensions.WriteByteLittle(bytes, offset, bccCode); return(offset); }