public MyDronePacket GeneratePacket( MyDronePacketContent contentid, byte[] content ) { MyDronePacket packet = new MyDronePacket( contentid, content ); var blob = BitConverter.GetBytes( ( ushort ) contentid ).Concat( content ).ToArray(); packet.CRC = ( ushort ) this.crcProvider.CalculateCRC( this.crcMode, blob, 0, blob.Length ); return packet; }
public static MyDronePacket DeSerialize( byte[] data ) { if ( null == data ) throw new ArgumentNullException( nameof( data ) ); MyDronePacket mdp = new MyDronePacket(); mdp.CRC = BitConverter.ToUInt16( data, 0 ); mdp.ContentID = ( MyDronePacketContent ) BitConverter.ToUInt16( data, 2 ); mdp.Data = data.Skip( 4 ).ToArray(); return mdp; }
public bool ValidatePacket( MyDronePacket packet ) { var blob = BitConverter.GetBytes( ( ushort ) packet.ContentID ).Concat( packet.Data ).ToArray(); return ( ushort ) this.crcProvider.CalculateCRC( this.crcMode, blob, 0, blob.Length ) == packet.CRC; }
public MyDronePacket GeneratePacket( MyDronePacketContent contentid ) { MyDronePacket packet = new MyDronePacket( contentid ); packet.CRC = ( ushort ) this.crcProvider.CalculateCRC( this.crcMode, BitConverter.GetBytes( ( ushort ) contentid ), 0, 2 ); return packet; }