using GeneralGommunication;
using System;
using System.ComponentModel;

namespace FlyADBase.Inc
{
    /// <summary>
    /// AD盒2021版.B2 , 核心模块 
    /// 实现AD盒2021版.B2 基本接口  
    /// </summary>
    public interface IFlyAd2021B2Core : IDev7E
    {
        #region AD盒 功能
        /// <summary>
        /// 数据推送事件
        /// </summary>
        event PushDataEventHandler PushDataEvent;
        /// <summary>
        /// 运行状态推送事件
        /// </summary>
        event PushRunResultEventHandler PushRunResultEvent;
        #region IOComm IO指令

        [CallBack(typeof(UInt16))]
        void GetIn(CallBackHandler asyncDelegate, object asyncContext);


        [CallBack(typeof(UInt16))]
        void GetOut(CallBackHandler asyncDelegate, object asyncContext);

        [CallBack(typeof(Int32))]
        void GetEnc1(CallBackHandler asyncDelegate, object asyncContext);

        [CallBack(typeof(Int32))]
        void GetEnc2(CallBackHandler asyncDelegate, object asyncContext);

        [CallBack(typeof(GetEncAll_Response))]
        void GetEncAll(CallBackHandler asyncDelegate, object asyncContext);

        void SetOutPorts(UInt16 mask, UInt16 value, CallBackHandler asyncDelegate, object asyncContext);
        #endregion

        #region RunComm 运行指令 SetRunParam

        void SetRunParam_V(UInt32 velocity, CallBackHandler asyncDelegate, object asyncContext);

        void SetRunParam_SV(UInt32 sv, CallBackHandler asyncDelegate, object asyncContext);

        void SetRunParam_AccTime(UInt32 accTime, CallBackHandler asyncDelegate, object asyncContext);

        void SetRunParam_DecTime(UInt32 decTime, CallBackHandler asyncDelegate, object asyncContext);

        void SetRunParam_HSpd1(UInt32 homespd1, CallBackHandler asyncDelegate, object asyncContext);

        void SetRunParam_HSpd2(UInt32 homespd2, CallBackHandler asyncDelegate, object asyncContext);
        #endregion

        #region RunComm 运行指令 GetRunParam
        void GetRunParam_V(CallBackHandler asyncDelegate, object asyncContext);

        void GetRunParam_SV(CallBackHandler asyncDelegate, object asyncContext);

        void GetRunParam_AccTime(CallBackHandler asyncDelegate, object asyncContext);

        void GetRunParam_DecTime(CallBackHandler asyncDelegate, object asyncContext);

        void GetRunParam_HSpd1(CallBackHandler asyncDelegate, object asyncContext);

        void GetRunParam_HSpd2(CallBackHandler asyncDelegate, object asyncContext);

        #endregion

        #region RunComm 运行指令

        [CallBack(typeof(GetRunResult_Response))]
        void GetRunResult(CallBackHandler asyncDelegate, object asyncContext);

        void Forw(Int32 serial, CallBackHandler asyncDelegate, object asyncContext);

        void Backw(Int32 serial, CallBackHandler asyncDelegate, object asyncContext);
        void Org(Int32 serial, CallBackHandler asyncDelegate, object asyncContext);

        void RunTo(Int32 serial, int targetPos, CallBackHandler asyncDelegate, object asyncContext);

        void Stop(CallBackHandler asyncDelegate, object asyncContext);

        void EStop(CallBackHandler asyncDelegate, object asyncContext);
        #endregion

        #region SysParamComm 系统参数指令

        /// <summary>
        /// 获取系统当前Tick
        /// </summary>
        [CallBack(typeof(UInt32))]
        void GetSysTick(CallBackHandler asyncDelegate, object asyncContext);

        #endregion
        
        #region GetSysParam 读运行参数
        [CallBack(typeof(MOTORTYPE))]
        void GetSysParam_MotorType(CallBackHandler asyncDelegate, object asyncContext);

        [CallBack(typeof(UInt16))]
        void GetSysParam_Ratio01(CallBackHandler asyncDelegate, object asyncContext);

        [CallBack(typeof(UInt16))]
        void GetSysParam_Ratio02(CallBackHandler asyncDelegate, object asyncContext);

        [CallBack(typeof(Int16))]
        void GetSysParam_Zero(CallBackHandler asyncDelegate, object asyncContext);

        [CallBack(typeof(UInt32))]
        void GetSysParam_Jog(CallBackHandler asyncDelegate, object asyncContext);
        #endregion

        #region SetSysParam 设置运行参数
        void SetSysParam_MotorType(MOTORTYPE motorType, CallBackHandler asyncDelegate, object asyncContext);


        void SetSysParam_Ratio01(UInt16 ratio01, CallBackHandler asyncDelegate, object asyncContext);

        void SetSysParam_Ratio02(UInt16 ratio02, CallBackHandler asyncDelegate, object asyncContext);

        void SetSysParam_Zero(Int16 zero, CallBackHandler asyncDelegate, object asyncContext);

        void SetSysParam_Jog(UInt32 jog, CallBackHandler asyncDelegate, object asyncContext);

        void SetSysParam_Apply(CallBackHandler asyncDelegate, object asyncContext);
        #endregion
        #endregion
    }


    public class PushDataEventArgs : EventArgs
    {
        public byte SysTick { get; set; }
        public UInt16 AD { get; set; }
        public UInt16 AD2 { get; set; }
        public UInt16? ENC1 { get; set; }
        public UInt16? ENC2 { get; set; }
        public UInt16? In { get; set; }
        public UInt16? InChange { get; set; }
        public UInt16? Out { get; set; }

        public PushDataEventArgs()
        {

        }
    }
    public delegate void PushDataEventHandler(object sender, PushDataEventArgs e);

    public class PushRunResultEventArgs : EventArgs
    {
        public byte SysTick { get; set; }
        /// <summary>
        /// 运行序号
        /// </summary>
        public UInt32 Serial { get; set; }

        /// <summary>
        /// 运行状态
        /// </summary>
        public DRIVE_MAN_STATUS Status { get; set; }
    }
    public delegate void PushRunResultEventHandler(object sender, PushRunResultEventArgs e);



    public class GetEncAll_Response
    {
        public int pos1;
        public int pos2;
    }

    public class GetRunResult_Response
    {
        public DRIVE_MAN_STATUS result;
        public UInt32 serial;
    }

    public class GetAccess_Response
    {
        public AREA_STATUS status;
        public AREA_ERR ret;
        public byte[] code = new byte[6];
        public UInt16 surplus;
        public byte[] access = new byte[8];
    }
}
