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_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); }
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_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_0x80Reply_0x81 value) { offset += JTNEBinaryExtensions.WriteBytesLittle(bytes, offset, value.ParamValue); 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); }