示例#1
0
 public byte[] Decode()
 {
     PacketContent = BinaryHelper.Reset(PacketContent, data);
     if(BinaryHelper.ReadByte(PacketContent, 3) == 0x01){
         AdditionalPacket = true;
     }else{
         AdditionalPacket = false;
     }
     FirstPacket = BinaryHelper.ReadTriad(PacketContent);
     if(!AdditionalPacket){
         LastPacket = BinaryHelper.ReadTriad(PacketContent);
     }
     return PacketContent.ToArray();
 }
 public void SetPacketCount(Triad PacketCount)
 {
 }
示例#3
0
 public void SetPacketCount(Triad PacketCount)
 {
     this.PacketCount = PacketCount;
 }
示例#4
0
 public void WriteTriad(Triad t, int index)
 {
     stream.Position = index;
     byte[] triadb = t.GetBytes();
     if(BitConverter.IsLittleEndian){
         Array.Reverse(triadb, 0, 3);
     }
     stream.Write(triadb, 0, 3);
 }
示例#5
0
 public void WriteTriad(Triad t)
 {
     byte[] triadb = t.GetBytes();
     if(BitConverter.IsLittleEndian){
         Array.Reverse(triadb, 0, 3);
     }
     stream.Write(triadb, 0, 3);
 }
 private void GeneratePayload()
 {
     packetLength = (short)(packetLength * 8); //LengthInBits = Length * 8
     byte[] dataLengthb = new byte[2];
     dataLengthb = BitConverter.GetBytes(packetLength);
     Array.Reverse(dataLengthb, 0, 2);
     stream.Write(dataLengthb, 0, 2); //Packet Length
     if(encapsulationFormat == 0x40){	//Encapsulation Format 0x40
         packetCount = new Triad(packetCount.ToInt32() + 1);
         byte[] packetCountb = new byte[3];
         packetCountb = packetCount.GetBytes();
         //Array.Reverse(packetCountb, 0, 3);
         stream.Write(packetCountb, 0, 3); //Packet Count
     }else if(encapsulationFormat == 0x60){	//Encapsulation Format 0x60
         packetCount2 = new Triad(packetCount.ToInt32() + 1);
         byte[] packetCountb = new byte[3];
         packetCountb = packetCount.GetBytes();
         Array.Reverse(packetCountb, 0, 3);
         stream.Write(packetCountb, 0, 3); //Packet Count
         stream.Write(new byte[]{0,0,0,0}, 0, 4); //Unknown
     }
 }
 public static EncapsulationHelper Encode(byte[] data, byte encapsulationFormat, Triad packetCount, byte customPacket)
 {
     EncapsulationHelper enchelper = new EncapsulationHelper();
     enchelper.stream = new MemoryStream();
     enchelper.isDecode = false;
     enchelper.customPacketID = customPacket;
     enchelper.stream.WriteByte(customPacket);
     enchelper.packetCount = packetCount;
     enchelper.encapsulationFormat = encapsulationFormat;
     enchelper.packetID = data[0];
     //Custom Packet Format
     byte[] packetCountb = new byte[3];
     packetCountb = packetCount.GetBytes();
     //Array.Reverse(packetCountb, 0, 3);
     enchelper.stream.Write(packetCountb, 0, 3);
     enchelper.stream.WriteByte(encapsulationFormat);
     enchelper.packetLength = (short) data.Length;
     enchelper.GeneratePayload();
     enchelper.stream.Write(data, 0, data.Length);
     return enchelper;
 }
 public static EncapsulationHelper Encode(byte[] data, byte encapsulationFormat, Triad packetCount)
 {
     return Encode(data, encapsulationFormat, new Triad(0), 0x80);
 }