COATINGSEGMENT_OBJ_INTERFACE.cs 4.57 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
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 COATINGSEGMENT_OBJ_INTERFACE
    {
        #region Pack
        public class Pack_Params : IPack
        {
            public bool enable;
            public bool enSave;
            public int saveCnt;
            public int recentCnt;
            public int inIdxOfVSide;
            public double warningtol_total;
            public double warningtol_distance;
            #region IPack 成员

            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();
                buf.AddRange(BitConverter.GetBytes(enable));
                buf.AddRange(BitConverter.GetBytes(enSave));
                buf.AddRange(BitConverter.GetBytes(saveCnt));
                buf.AddRange(BitConverter.GetBytes(recentCnt));
                buf.AddRange(BitConverter.GetBytes(inIdxOfVSide));
                buf.AddRange(BitConverter.GetBytes(warningtol_total));
                buf.AddRange(BitConverter.GetBytes(warningtol_distance));
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {
                if (value.Length < (1 * 2 + 4 * 3 + 8 * 2))
                    return false;
                int idx = 0;
                enable = BitConverter.ToBoolean(value, idx);
                idx++;

                enSave = BitConverter.ToBoolean(value, idx);
                idx++;

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

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

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


                warningtol_total = BitConverter.ToDouble(value, idx);
                idx += 8;

                warningtol_distance = BitConverter.ToDouble(value, idx);
                idx += 8;
                return true;
            }

            #endregion
        }
        public class Pack_Recent : IPack
        {
            public FlyData_CoatingSegmentHistory[] data;
            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();
                buf.AddRange(BitConverter.GetBytes(data.Count()));
                for (int i = 0; i < data.Count(); i++)
                {
                    buf.AddRange(data[i].ToBytes());
                }
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {

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


                int idx = 0;
                int length = BitConverter.ToInt32(value, idx);
                idx += 4;
                data = new FlyData_CoatingSegmentHistory[length];
                for (int i = 0; i < length; i++)
                {
                    data[i] = new FlyData_CoatingSegmentHistory();
                    int count;
                    if (!data[i].TryParse(value, idx, out count))
                        return false;

                    idx += count;
                    cnt += count;
                }
                return true;
            }
        }
        
        #endregion

        #region GetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 GET_PARAMS = 0;
        /// <summary>
        /// CoatingSegmentProfile
        /// </summary>
        public const UInt16 GET_PROFILE = 1;
        /// <summary>
        /// FlyData_CoatingSegmentHistory
        /// </summary>
        public const UInt16 GET_LAST = 2;
        #endregion
        #region SetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 SET_PARAMS = 0;
        /// <summary>
        /// CoatingSegmentProfile
        /// </summary>
        public const UInt16 SET_PROFILE = 1;
        #endregion
        #region PushMsg
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 PUSH_PARAMS = 0;
        /// <summary>
        /// CoatingSegmentProfile       
        /// </summary>
        public const UInt16 PUSH_PROFILE = 1;
        /// <summary>
        /// FlyData_CoatingSegmentHistory
        /// </summary>
        public const UInt16 PUSH_LAST = 2;
        #endregion
        #region CallFunction
        /// <summary>
        /// request:null
        /// reponse:Pack_Recent
        /// </summary>
        public const UInt16 CALL_GETRECENT = 1;
        #endregion
    }
}