zoukankan      html  css  js  c++  java
  • Packet_TS.cs

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Bit;
    
    namespace Packet
    {
        class Packet_TS
        {
            BitOperation bitOperarion = new BitOperation();
    
            public Packet_TS(Byte[] bytes)
            {
                _TSBytes = bytes;
    
                _list_data_bytes = new List<byte>();
                for (int i = 5; i < bytes.Length ; i++)  //把data字节数组填充为0
                {
                    _list_data_bytes.Add(bytes[i]);
                }
    
            }
    
            private Byte[] _TSBytes;
            ///////////////////TS Header/////////////////////
            private Byte _sync_byte;
            private Byte _transport_error_indicator;
            private Byte _payload_unit_start_indicator;
            private Byte _transport_priority;
            private UInt16 _PID;
            private Byte _transport_scrambling_control;
            private Byte _adaption_field_control;
            private Byte _continuity_counter;
    
            ///////////////////Data//////////////////////////
            private Byte _position_indicator;
            private List<Byte> _list_data_bytes;
    
            ///////////////////get set方法///////////////////
            public Byte[] TSBytes
            {
                get
                {
                    return this._TSBytes;
                }
                set
                {
                    this._TSBytes = value;
                }
            }
            public Byte Sync_Byte
            {
                get
                {
                    this._sync_byte = Convert.ToByte(_TSBytes[0]);
                    return this._sync_byte;
                }
                set
                {
                    this._sync_byte = value;
                    this._TSBytes[0] = value;
                }
            }
            public Byte Transport_Error_Indicator
            {
                get
                {
                    this._transport_error_indicator = Convert.ToByte(_TSBytes[1] >> 7);
                    return this._transport_error_indicator;
                }
                set
                {
                    this._transport_error_indicator = value;
    
                    this._TSBytes[1] = bitOperarion.setBit(_TSBytes[1], 0, value);
                }
            }
            public Byte Payload_Unit_Start_Indicator
            {
                get
                {
                    this._payload_unit_start_indicator = Convert.ToByte((_TSBytes[1] >> 6) & 0x01);
                    return this._payload_unit_start_indicator;
                }
                set
                {
                    this._payload_unit_start_indicator = value;
    
                    this._TSBytes[1] = bitOperarion.setBit(_TSBytes[1], 1, value);
                }
            }
            public Byte Transport_Priority
            {
                get
                {
                    this._transport_priority = Convert.ToByte((_TSBytes[1] >> 5) & 0x01);
                    return this._transport_priority;
                }
                set
                {
                    this._transport_priority = value;
    
                    this._TSBytes[1] = bitOperarion.setBit(_TSBytes[1], 2, value);
                }
            }
            public UInt16 Pid
            {
                get
                {
                    UInt16 high = Convert.ToUInt16((_TSBytes[1] & 0x1F) << 8);
                    UInt16 low = Convert.ToUInt16(_TSBytes[2]);
                    this._PID = Convert.ToUInt16(high | low);
                    return this._PID;
                }
                set
                {
                    this._PID = value;
                    Byte high = Convert.ToByte(value >> 8);
                    Byte low = Convert.ToByte(value & 0x00ff);
                    for (int i = 3; i < 8; i++)
                    {
                        int temp = bitOperarion.getBit(high, i);
                        this._TSBytes[1] = bitOperarion.setBit(this._TSBytes[1], i, temp);
                    }
                    this._TSBytes[2] = low;
                }
            }
            public Byte Transport_Scrambling_Control
            {
                get
                {
                    this._transport_scrambling_control = Convert.ToByte((_TSBytes[3] >> 6) & 0x03);
                    return this._transport_scrambling_control;
                }
                set
                {
                    this._transport_scrambling_control = value;
    
                    this._TSBytes[3] = bitOperarion.setBit( _TSBytes[3], 0, (value >> 1) & 0x01 );
                    this._TSBytes[3] = bitOperarion.setBit( _TSBytes[3], 1, (value & 0x01) );
                }
            }
            public Byte Adaption_Field_Control
            {
                get
                {
                    this._continuity_counter = Convert.ToByte((_TSBytes[3] >> 4) & 0x03);
                    return this._continuity_counter;
                }
                set
                {
                    this._continuity_counter = value;
    
                    this._TSBytes[3] = bitOperarion.setBit( _TSBytes[3], 2, (value >> 1) & 0x01 );
                    this._TSBytes[3] = bitOperarion.setBit( _TSBytes[3], 3, (value & 0x01) );
                }
            }
            public Byte Continuity_Counter
            {
                get
                {
                    this._adaption_field_control = Convert.ToByte(_TSBytes[3] & 0x0f);
                    return this._adaption_field_control;
                }
                set
                {
                    this._adaption_field_control = value;
    
                    for (int i = 4; i < 8; i++)
                    {
                        int temp = bitOperarion.getBit(value, i);
                        this._TSBytes[3] = bitOperarion.setBit(this._TSBytes[3], i, temp);
                    }
                }
            }
            public Byte Position_Indicator
            {
                get
                {
                    this._position_indicator = Convert.ToByte(_TSBytes[4]);
                    return this._position_indicator;
                }
                set
                {
                    this._position_indicator = value;
                    this._TSBytes[4] = value;
                }
            }
            public List<Byte> List_Data_Bytes
            {
                get
                {
                    return this._list_data_bytes;
                }
                set
                {
                    this._list_data_bytes = value;
                }
            }
    
            ///////////////////字节中的比特位操作///////////////////
        }
    }
    
  • 相关阅读:
    洛谷P1020/CODEVS1044 导弹拦截(拦截导弹)
    洛谷P1541/CODEVS1068 乌龟棋
    洛谷1791/CODEVS1214线段覆盖
    NOIP2002提高组/洛谷P1031均分纸牌
    【USACO2009Decsilver T1 自私的食草者
    洛谷P1024/NOI题库7891(2.3)/NOIP2001提高组T1 一元三次方程求解
    洛谷1086/NOI题库1.13.38/NOIP2004普及组第2题 花生采摘
    NOIP2010/洛谷P1525关押罪犯
    洛谷P1115最大子段和
    1244-作为一个java开发者的知识储备
  • 原文地址:https://www.cnblogs.com/jingmoxukong/p/2121289.html
Copyright © 2011-2022 走看看