Packet.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Net;
using Bit;

namespace Packet
{
    

    public class TSPacket
    {
        BitOperation bitOperarion = new BitOperation();

        public TSPacket(Byte[] bytes)
        {
            TSBytes = bytes;
            _data = new Byte[183];
            for (int i = 0; i < _data.Length; i++)  //把data字节数组填充为0
            {
                _data[i] = 0; 
            }
        }

        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 Byte[] _data;

        ///////////////////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 Byte[] DATA
        {
            get
            {
                return this._data;
            }
            set
            {
                this._data = value;
            }
        }

        ///////////////////字节中的比特位操作///////////////////
        
    }

   
   
    public class PMT
    {
        //public static string table_id = "00000010";
        //public static string section_syntax_indicator = "1";
        //public static string zero = "0";
        //public static string reserved = "00";
        //public static string section_length = "111111111111";
        //public static string program_number = "0000000000000001";
        //public static string reserved2 = "00";
        //public static string version_number = "00001";
        //public static string current_next_indicator = "0";
        //public static string section_number = "00000001";
        //public static string last_section_number = "00000000";
        //public static string reserved3 = "000";
        //public static string PCR_PID = "0000000000001";
        //public static string reserved4 = "0000";
        //public static string program_info_length = "111111111111";
    }

    public class SDT
    { }

    public struct CDT
    {
        //public static string table_id = "11001000";
        //public static string section_syntax_indicator = "1";
        //public static string reserved_future_use = "0";
        //public static string reserved = "00";
        //public static string section_length = "111111111111";
        //public static string download_data_id = "0000000000000001";
        //public static string reserved2 = "00";
        //public static string vesion_number = "00001";
        //public static string current_next_indicator = "1";
        //public static string section_number = "00000001";
        //public static string last_section_number = "00000000";
        //public static string original_netword_id = "0000000000000000";
        //public static string data_type = "00000000";
        //public static string reserved_future_use2 = "0000";
        //public static string descriptors_loop_length = "000000000000";

        //public static string CDTTableStr = table_id + section_syntax_indicator
        //   + reserved_future_use + reserved + section_length
        //   + download_data_id + reserved2 + vesion_number + current_next_indicator
        //   + section_number + last_section_number + original_netword_id
        //   + data_type + reserved_future_use2 + descriptors_loop_length;  
    }

    public class SDTT
    { }
}
在 System.IO.Ports.SerialStream.Write(Byte[] array, Int32 offset, Int32 count, Int32 timeout) 在 System.IO.Ports.SerialPort.Write(Byte[] buffer, Int32 offset, Int32 count) 在 MissionPlanner.Comms.WinSerialPort.MissionPlanner.Comms.ICommsSerial.Write(Byte[] buffer, Int32 offset, Int32 count) 在 MissionPlanner.Comms.SerialPort.Write(Byte[] buffer, Int32 offset, Int32 count) 位置 C:\Users\mich1\Desktop\CubePilot\MissionPlanner\ExtLibs\Comms\CommsSerialPort.cs:行号 183 在 MissionPlanner.MAVLinkInterface.generatePacket(Int32 messageType, Object indata, Int32 sysid, Int32 compid, Boolean forcemavlink2, Boolean forcesigning) 位置 C:\Users\mich1\Desktop\CubePilot\MissionPlanner\ExtLibs\ArduPilot\Mavlink\MAVLinkInterface.cs:行号 1368 在 MissionPlanner.MAVLinkInterface.sendPacket(Object indata, Int32 sysid, Int32 compid) 位置 C:\Users\mich1\Desktop\CubePilot\MissionPlanner\ExtLibs\ArduPilot\Mavlink\MAVLinkInterface.cs:行号 1157 在 MissionPlanner.MAVLinkInterface.<getHeartBeatAsync>d__153.MoveNext() 位置 C:\Users\mich1\Desktop\CubePilot\MissionPlanner\ExtLibs\ArduPilot\Mavlink\MAVLinkInterface.cs:行号 1087 --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 MissionPlanner.Utilities.Extensions.<>c__DisplayClass1_0`1.<<AwaitSync>b__0>d.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 MissionPlanner.Utilities.Extensions.AwaitSync[T](Task`1 infunc) 在 MissionPlanner.MAVLinkInterface.OpenBg(IProgressReporterDialogue PRsender, Boolean getparams) 位置 C:\Users\mich1\Desktop\CubePilot\MissionPlanner\ExtLibs\ArduPilot\Mavlink\MAVLinkInterface.cs:行号 886 在 MissionPlanner.Controls.ProgressReporterDialogue.RunBackgroundOperation(Object o) 位置 C:\Users\mich1\Desktop\CubePilot\MissionPlanner\ExtLibs\Controls\ProgressReporterDialogue.cs:行号 111
04-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值