using Plane.Protocols;
using System.Collections;
using System.Collections.Generic;
using TaskTools.Attributes;

namespace Plane.Copters
{
    partial class PlaneCopter
    {
        public class Mavlink_Sensors
        {
            BitArray bitArray = new BitArray(32);

            public Mavlink_Sensors()
            {
            }

            public Mavlink_Sensors(uint p)
            {
                bitArray = new BitArray(new int[] { (int)p });
            }

            public bool gyro { get { return bitArray[0]; } set { bitArray[0] = value; } }
            public bool accelerometer { get { return bitArray[1]; } set { bitArray[1] = value; } }
            public bool compass { get { return bitArray[2]; } set { bitArray[2] = value; } }
            public bool barometer { get { return bitArray[3]; } set { bitArray[3] = value; } }
            public bool differential_pressure { get { return bitArray[4]; } set { bitArray[4] = value; } }
            public bool gps { get { return bitArray[5]; } set { bitArray[5] = value; } }
            public bool optical_flow { get { return bitArray[6]; } set { bitArray[6] = value; } }
            public bool unused_7 { get { return bitArray[7]; } set { bitArray[7] = value; } }
            public bool CanTakeOff { get { return bitArray[8]; } set { bitArray[8] = value; } }
            public bool unused_9 { get { return bitArray[9]; } set { bitArray[9] = value; } }
            public bool rate_control { get { return bitArray[10]; } set { bitArray[10] = value; } }
            public bool attitude_stabilization { get { return bitArray[11]; } set { bitArray[11] = value; } }
            public bool yaw_position { get { return bitArray[12]; } set { bitArray[12] = value; } }
            public bool altitude_control { get { return bitArray[13]; } set { bitArray[13] = value; } }
            public bool xy_position_control { get { return bitArray[14]; } set { bitArray[14] = value; } }
            public bool motor_control { get { return bitArray[15]; } set { bitArray[15] = value; } }
            public bool rc_receiver { get { return bitArray[16]; } set { bitArray[16] = value; } }

            public int Value
            {
                get
                {
                    int[] array = new int[1];
                    ((ICollection)bitArray).CopyTo(array, 0);
                    return array[0];
                }
                // 林俊清，20150703：BitArray 的构造函数的参数是数组长度，这里根本不对啊。
                //set
                //{
                //    bitArray = new BitArray(value);
                //}
            }
        }

        public class MAVState
        {
            public MAVState()
            {
                sysid = 0;
                compid = 0;
                param = new Dictionary<string, float>();
                packets = new byte[0x100][];
                packetseencount = new int[0x100];
                aptype = 0;
                apname = 0;
                recvpacketcount = 0;
            }

            /// <summary>
            /// the static global state of the currently connected MAV
            /// </summary>
            //public CurrentState cs = new CurrentState();
            /// <summary>
            /// mavlink remote sysid
            /// </summary>
            public byte sysid { get; set; }
            /// <summary>
            /// mavlink remove compid
            /// </summary>
            public byte compid { get; set; }
            /// <summary>
            /// storage for whole paramater list
            /// </summary>
            public Dictionary<string, float> param { get; set; }
            /// <summary>
            /// storage of a previous packet recevied of a specific type
            /// </summary>
            public byte[][] packets { get; set; }
            public int[] packetseencount { get; set; }
            /// <summary>
            /// mavlink ap type
            /// </summary>
            public MAVLink.MAV_TYPE aptype { get; set; }
            public MAVLink.MAV_AUTOPILOT apname { get; set; }
            /// <summary>
            /// used as a snapshot of what is loaded on the ap atm. - derived from the stream
            /// </summary>
            public Dictionary<int, MAVLink.mavlink_mission_item_t> wps = new Dictionary<int, MAVLink.mavlink_mission_item_t>();

            public Dictionary<int, MAVLink.mavlink_rally_point_t> rallypoints = new Dictionary<int, MAVLink.mavlink_rally_point_t>();

            public Dictionary<int, MAVLink.mavlink_fence_point_t> fencepoints = new Dictionary<int, MAVLink.mavlink_fence_point_t>();

            /// <summary>
            /// Store the guided mode wp location
            /// </summary>
            public MAVLink.mavlink_mission_item_t GuidedMode = new MAVLink.mavlink_mission_item_t();

            internal int recvpacketcount = 0;
        }

        public enum sensoroffsetsenum
        {
            gyro = 0,
            accelerometer = 1,
            magnetometer = 2,
            barometer = 3,
            optical_flow = 4,
            second_magnetometer = 5
        }

        public enum ac2modes
        {
            [DisplayText("STABILIZE")]
            STABILIZE = 0,			// hold level position
            [DisplayText("ACRO")]
            ACRO = 1,			// rate control
            [DisplayText("ALT HOLD")]
            ALT_HOLD = 2,		// AUTO control
            [DisplayText("AUTO")]
            AUTO = 3,			// AUTO control
            [DisplayText("GUIDED")]
            GUIDED = 4,		// AUTO control
            [DisplayText("LOITER")]
            LOITER = 5,		// Hold a single location
            [DisplayText("RTL")]
            RTL = 6,				// AUTO control
            [DisplayText("CIRCLE")]
            CIRCLE = 7,
            [DisplayText("POS HOLD")]
            POSITION = 8,
            [DisplayText("LAND")]
            LAND = 9,				// AUTO control
            OF_LOITER = 10,
            [DisplayText("TOY")]
            TOY = 11
        }

        public enum ac2modes_cn
        {
            [DisplayText("增稳模式")]
            STABILIZE = 0,			// hold level position
            [DisplayText("ACRO")]
            ACRO = 1,			// rate control
            [DisplayText("定高模式")]
            ALT_HOLD = 2,		// AUTO control
            [DisplayText("自动航线")]
            AUTO = 3,			// AUTO control
            [DisplayText("指令模式")]
            GUIDED = 4,		// AUTO control
            [DisplayText("定点定高")]
            LOITER = 5,		// Hold a single location
            [DisplayText("返航模式")]
            RTL = 6,				// AUTO control
            [DisplayText("盘旋模式")]
            CIRCLE = 7,
            [DisplayText("位置保持")]
            POSITION = 8,
            [DisplayText("降落")]
            LAND = 9,				// AUTO control
            OF_LOITER = 10,
            [DisplayText("玩具")]
            TOY = 11
        }
    }
}
