using FLY.Thick.Blowing.IService;
using FObjBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FLY.Thick.Blowing.OBJ_INTERFACE
{
    /// <summary>
    /// 吹膜测厚 OBJ接口
    /// </summary>
    public class BLOWING_OBJ_INTERFACE
    {
        #region Pack
        public class Pack_Params : IPack
        {
            /// <summary>
            /// 加热棒数量
            /// </summary>
            public int channelcnt;
            /// <summary>
            /// 分区数/加热棒数量
            /// </summary>
            public int bpc;
            /// <summary>
            /// 复位区号
            /// </summary>
            public int orgBolt;

            #region IPack 成员

            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();
                buf.AddRange(BitConverter.GetBytes(channelcnt));
                buf.AddRange(BitConverter.GetBytes(bpc));
                buf.AddRange(BitConverter.GetBytes(orgBolt));
                return buf.ToArray();
            }


            public bool TryParse(byte[] value)
            {
                if (value.Length < 4 + 4 + 4)
                    return false;
                int idx = 0;

                channelcnt = BitConverter.ToInt32(value, idx);
                idx += 4;

                bpc = BitConverter.ToInt32(value, idx);
                idx += 4;

                orgBolt = BitConverter.ToInt32(value, idx);
                idx += 4;

                return true;
            }

            #endregion
        }
        public class Pack_Map : IPack
        {
            public bool IsUsedMap;
            public List<BoltMapCell> Map;

            #region IPack 成员

            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();
                buf.AddRange(BitConverter.GetBytes(IsUsedMap));

                if (Map != null)
                {
                    int len = Map.Count();
                    buf.AddRange(BitConverter.GetBytes(len));
                    for (int i = 0; i < len; i++)
                    {
                        buf.AddRange(Map[i].ToBytes());
                    }
                }
                else
                {
                    buf.AddRange(BitConverter.GetBytes(0));
                }
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {
                int cnt = 1;
                if (value.Length < cnt)
                    return false;

                int idx = 0;
                IsUsedMap = BitConverter.ToBoolean(value, idx);
                idx += 1;

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

                int len = BitConverter.ToInt32(value, idx);
                idx += 4;
                if (len > 0)
                {
                    cnt += len * 8;

                    if (value.Length < cnt)
                        return false;
                    List<BoltMapCell> map = new List<BoltMapCell>();

                    for (int i = 0; i < len; i++)
                    {
                        map.Add(new BoltMapCell());
                        map[i].TryParse(value, idx);
                        idx += 8;
                    }
                    Map = map;
                }
                else
                {
                    Map = new List<BoltMapCell>();
                }
                return true;
            }

            #endregion

        }
        #endregion
        #region GetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 GET_PARAMS = 1;
        /// <summary>
        /// Pack_Map
        /// </summary>
        public const UInt16 GET_MAP = 2;
        #endregion
        #region SetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 SET_PARAMS = 1;
        /// <summary>
        /// Pack_Map
        /// </summary>
        public const UInt16 SET_MAP = 2;
        #endregion

        #region PushInfo
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 PUSH_PARAMS = 1;
        /// <summary>
        /// Pack_Map
        /// </summary>
        public const UInt16 PUSH_MAP = 2;
        /// <summary>
        /// Pack_RenZiJiaDataEventArgs
        /// </summary>
        public const UInt16 PUSH_DATA = 10;


        #endregion

        #region CallFunction


        #endregion

    }
}