using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
using FObjBase;
using FObjBase.Reflect;
using System;

namespace FLY.Thick.Base.Client
{
    public class FlyADServiceClient : FObjBase.Reflect.Reflect_SeviceClient, IFlyADService
    {
        protected override Type InterfaceType => typeof(IFlyADService);
        public FlyADServiceClient(UInt32 serviceId) : base(serviceId) { }
        public FlyADServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
        #region IFlyAD接口


        public string Addr { get; set; }

        public bool HasCRC { get; set; }


        /// <summary>
        /// grid数据平滑
        /// </summary>
        public int GridSmooth { get; set; }

        /// <summary>
        /// 通过脉冲计算速度，不使用AD盒的输出
        /// </summary>
        public bool IsCalSpeed { get; set; }

        public int PosLen { get; set; }

        public MOTORTYPE MotorType { get; set; }

        /// <summary>
        /// // 单位 pulse/grid
        /// </summary>
        public UInt16 PosOfGrid { get; set; }

        public UInt16 Ratio01 { get; set; }


        public UInt16 Ratio02 { get; set; }


        public Int16 PosOffset { get; set; }


        /// <summary>
        /// 脉冲平移
        /// </summary>
        public UInt32 JogVelocity { get; set; }
        public int ADLag { get; set; }
        /// <summary>
        /// 参数应用
        /// </summary>
        public void Apply()
        {
            Call(nameof(Apply));
        }
        /// <summary>
        /// 获取序列码
        /// </summary>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        [Call(typeof(AccessInfo))]
        public void GetAccessInfo(AsyncCBHandler asyncDelegate, object asyncContext)
        {
            Call(nameof(GetAccessInfo), null, asyncDelegate, asyncContext);
        }
        /// <summary>
        /// 设置授权码
        /// </summary>
        /// <param name="access"></param>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        [Call(typeof(AccessInfo))]
        public void SetAccess(byte[] access, AsyncCBHandler asyncDelegate, object asyncContext)
        {
            Call(nameof(SetAccess), new { access }, asyncDelegate, asyncContext);
        }

        /// <summary>
        /// 获取grid
        /// </summary>
        /// <param name="direction"></param>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        [Call(typeof(byte[]))]
        public void GetGrid(Misc.DIRECTION direction, AsyncCBHandler asyncDelegate, object asyncContext)
        {
            Call(nameof(SetAccess), new { direction }, asyncDelegate, asyncContext);
        }


        /// <summary>
        /// 向AD盒获取数据
        /// </summary>
        public void UpdateParam()
        {
            Call(nameof(UpdateParam));
        }
        #endregion
    }
}