using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;
using FLY.Thick.Base.Common;

namespace FLY.Thick.Base.OBJ_INTERFACE
{
    public class INITPARAM_OBJ_INTERFACE
    {
        public const UInt32 ID = OBJ_INTERFACE_ID.INITPARAM_ID;
        #region Pack
        public class Pack_Params : IPack
        {
            public int poslength;

            public int auto_org_interval;
            public double encoder1_mmpp;

            public int adlag;
            public int posOfGrid;
            public double speed1scale;



            public FilmVSRC filmVSrc;
            public int filmVThreshold;
            public double encoder2_mmpp;
            public float encoder2_comp;
            public double mmOfR;
            public int inIdxOfRound;
            public DATAVALIDSRC data_valid_src;

            public bool autof1f3;
            public int restartDelay;


            public UInt32 vscan;
            public UInt32 vjog;
            public UInt32 vaccuracy;
            public UInt32 svelocity;
            public UInt32 atime;
            public UInt32 dtime;
            public UInt32 hvelocity1;
            public UInt32 hvelocity2;


            public bool hasProfileSample;
            public bool hasHold;

            #region IPack 成员

            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();
                buf.AddRange(BitConverter.GetBytes(poslength));
                buf.AddRange(BitConverter.GetBytes(adlag));
                buf.AddRange(BitConverter.GetBytes(auto_org_interval));
                buf.AddRange(BitConverter.GetBytes(posOfGrid));
                buf.AddRange(BitConverter.GetBytes(encoder1_mmpp));
                buf.AddRange(BitConverter.GetBytes(speed1scale));


                buf.AddRange(BitConverter.GetBytes((int)filmVSrc));
                buf.AddRange(BitConverter.GetBytes(filmVThreshold));
                buf.AddRange(BitConverter.GetBytes(encoder2_mmpp));
                buf.AddRange(BitConverter.GetBytes(encoder2_comp));
                buf.AddRange(BitConverter.GetBytes(mmOfR));
                buf.AddRange(BitConverter.GetBytes((int)data_valid_src));

                buf.AddRange(BitConverter.GetBytes(autof1f3));
                buf.AddRange(BitConverter.GetBytes(restartDelay));


                buf.AddRange(BitConverter.GetBytes(vscan));
                buf.AddRange(BitConverter.GetBytes(vjog));
                buf.AddRange(BitConverter.GetBytes(vaccuracy));

                buf.AddRange(BitConverter.GetBytes(svelocity));
                buf.AddRange(BitConverter.GetBytes(atime));
                buf.AddRange(BitConverter.GetBytes(dtime));
                buf.AddRange(BitConverter.GetBytes(hvelocity1));
                buf.AddRange(BitConverter.GetBytes(hvelocity2));



                buf.AddRange(BitConverter.GetBytes(hasProfileSample));
                buf.AddRange(BitConverter.GetBytes(hasHold));
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {
                int cnt = 4 * 4 + 8 * 2;
                if (value.Length <cnt)
                    return false;
                int idx = 0;
                poslength = BitConverter.ToInt32(value, idx);
                idx += 4;
                adlag = BitConverter.ToInt32(value, idx);
                idx += 4;
                auto_org_interval = BitConverter.ToInt32(value, idx);
                idx += 4;
                posOfGrid = BitConverter.ToInt32(value, idx);
                idx += 4;
                encoder1_mmpp = BitConverter.ToDouble(value, idx);
                idx += 8;
                speed1scale = BitConverter.ToDouble(value, idx);
                idx += 8;

                cnt += 4 + 4 + 8 + 4 + 8 + 4;
                if (value.Length < cnt)
                    return false;

                filmVSrc = (FilmVSRC)BitConverter.ToInt32(value, idx);
                idx += 4;
                filmVThreshold = BitConverter.ToInt32(value, idx);
                idx += 4;
                encoder2_mmpp = BitConverter.ToDouble(value, idx);
                idx += 8;
                encoder2_comp = BitConverter.ToSingle(value, idx);
                idx += 4;
                mmOfR = BitConverter.ToDouble(value, idx);
                idx += 8;
                data_valid_src = (DATAVALIDSRC)BitConverter.ToInt32(value, idx);
                idx += 4;


                cnt += 1 + 4;
                if (value.Length < cnt)
                    return false;
                autof1f3 = BitConverter.ToBoolean(value, idx);
                idx++;
                restartDelay = BitConverter.ToInt32(value, idx);
                idx += 4;

                cnt += 4 * 8;
                if (value.Length < cnt)
                    return false;
                vscan = BitConverter.ToUInt32(value, idx);
                idx += 4;
                vjog = BitConverter.ToUInt32(value, idx);
                idx += 4;
                vaccuracy = BitConverter.ToUInt32(value, idx);
                idx += 4;

                svelocity = BitConverter.ToUInt32(value, idx);
                idx += 4;
                atime = BitConverter.ToUInt32(value, idx);
                idx += 4;
                dtime = BitConverter.ToUInt32(value, idx);
                idx += 4;
                hvelocity1 = BitConverter.ToUInt32(value, idx);
                idx += 4;
                hvelocity2 = BitConverter.ToUInt32(value, idx);
                idx += 4;



                cnt += 2;
                if (value.Length < cnt)
                    return false;

                hasProfileSample = BitConverter.ToBoolean(value, idx);
                idx++;
                hasHold = BitConverter.ToBoolean(value, idx);
                idx++;



                return true;
            }

            #endregion
        }
        #endregion

        #region GetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 GET_PARAMS = 0;
        #endregion
        #region SetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 SET_PARAMS = 0;
        #endregion
        #region PushMsg
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 PUSH_PARAMS = 0;
        #endregion
    }
}
