HeatBufServiceClient.cs 11.9 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12
using FLY.FeedbackRenZiJia.Common;
using FLY.FeedbackRenZiJia.IService;
using FLY.FeedbackRenZiJia.OBJ_INTERFACE;
using FObjBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace FLY.FeedbackRenZiJia.Client
{
13
    public class HeatBufServiceClient : FObjServiceClient, IHeatBufService
潘栩锋's avatar
潘栩锋 committed
14 15 16 17 18 19 20
    {

        #region 属性,对外接口
        #region 参数
        /// <summary>
        /// 加热生效曲线,允许为空,则不生效
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
21 22 23
        [PropertyChanged.DoNotCheckEquality]
        public List<int> HeatEffectCurve { get; set; } = new List<int>();

潘栩锋's avatar
潘栩锋 committed
24 25 26 27

        /// <summary>
        /// 厚度稳定范围 %, 偏差在范围内,都是稳定的 
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
28 29
        public int StableRange { get; set; } = 2;

潘栩锋's avatar
潘栩锋 committed
30 31 32 33

        /// <summary>
        /// 厚度稳定范围 %, 加热量变化为0时,偏差在范围内,都是稳定的 
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
34 35
        public int StableRange0 { get; set; } = 2;

潘栩锋's avatar
潘栩锋 committed
36 37 38 39

        /// <summary>
        /// 对位模式, 加热与厚度相关性阀值, 相关性 >=0.7
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
40 41
        public double ThresholdR { get; set; } = 0.7;

潘栩锋's avatar
潘栩锋 committed
42 43 44 45

        /// <summary>
        /// 对位模式 厚度%差 的极差 >= +4%-4%=8%, 单位%
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
46 47
        public int ThresholdMaxMin { get; set; } = 8;

潘栩锋's avatar
潘栩锋 committed
48 49 50 51 52

        /// <summary>
        /// %
        /// 最大sigma, 只有当前的sigma  在 最大sigma 与 最小 sigma 内,才能控制
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
53 54
        public int ThresholdSigmaMax { get; set; } = 20;

潘栩锋's avatar
潘栩锋 committed
55 56 57 58 59

        /// <summary>
        /// %
        /// 最小sigma, 只有当前的sigma  在 最大sigma 与 最小 sigma 内,才能控制
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
60 61
        public double ThresholdSigmaMin { get; set; } = 2;
        
潘栩锋's avatar
潘栩锋 committed
62 63 64
        /// <summary>
        /// 使用这里独立的Kp, 与 HeatCell 不一样
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
65 66 67
        public bool IsUsedLocalKp { get; set; }


潘栩锋's avatar
潘栩锋 committed
68 69 70 71

        /// <summary>
        /// 本地Kp, 用于判断稳定性
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
72 73
        public double LocalKp { get; set; } = 3;

潘栩锋's avatar
潘栩锋 committed
74 75 76 77
        #endregion

        #region 状态

潘栩锋's avatar
潘栩锋 committed
78

潘栩锋's avatar
潘栩锋 committed
79 80 81
        /// <summary>
        /// 总延时 =Delay+mRenZiJiaService.FilmLength/mRenZiJiaService.Velocity
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
82
        public TimeSpan Delay { get; set; } = TimeSpan.FromSeconds(100);
潘栩锋's avatar
潘栩锋 committed
83 84

        #region 对位
潘栩锋's avatar
潘栩锋 committed
85

潘栩锋's avatar
潘栩锋 committed
86 87 88
        /// <summary>
        /// 进入了对位模式
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
89
        public bool IsIntoAutoONo { get; set; }
潘栩锋's avatar
潘栩锋 committed
90 91 92
        /// <summary>
        /// 对位模式结果
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
93 94
        public EAutoONoResult AutoONoResult { get; set; } = EAutoONoResult.Idle;

潘栩锋's avatar
潘栩锋 committed
95 96 97 98

        /// <summary>
        /// 计算的最佳复位区号
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
99
        public int BestOrgBoltNo { get; set; } = -1;
潘栩锋's avatar
潘栩锋 committed
100 101 102 103

        /// <summary>
        /// 计算的最佳复位区号 对应的 加热/厚度 
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
104 105
        public double BestKp { get; set; } = -1;

潘栩锋's avatar
潘栩锋 committed
106 107 108 109

        /// <summary>
        /// 计算的最佳复位区号 对应的 加热与厚度相关性
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
110 111
        public double MaxR { get; set; } = -1;

潘栩锋's avatar
潘栩锋 committed
112 113 114 115

        /// <summary>
        /// 计算的最佳复位区号 对应的 厚度%变化极差 单位%
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
116 117
        public double MaxMin { get; set; } = -1;

潘栩锋's avatar
潘栩锋 committed
118 119 120
        #endregion

        #region 稳定性
潘栩锋's avatar
潘栩锋 committed
121

潘栩锋's avatar
潘栩锋 committed
122 123 124
        /// <summary>
        /// 当前检测出来的厚度数据 稳定状态
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
125 126 127
        public STABILITY Stability { get; protected set; } = STABILITY.IDLE;


潘栩锋's avatar
潘栩锋 committed
128 129 130 131

        /// <summary>
        /// 当前检测出来的厚度数据 的稳定性 
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
132 133
        public double CurrR { get; protected set; } = -1;

潘栩锋's avatar
潘栩锋 committed
134 135 136 137

        /// <summary>
        /// 当前检测出来的厚度数据 2Sigma
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
138 139 140
        public double Curr2Sigma { get; protected set; } = -1;


潘栩锋's avatar
潘栩锋 committed
141 142 143 144 145 146
        /// <summary>
        /// 当前打散程度。 
        /// 连续N点都在平均值同一侧为一个块;
        /// 这些块的长度平均值/总长度, 为打散度;
        /// 打散度越小越好, 最小为 1/NBolts
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
147 148 149
        public double CurrBreakUp { get; protected set; } = 50;


潘栩锋's avatar
潘栩锋 committed
150 151 152
        /// <summary>
        /// 当前检测出来的厚度数据,时间
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
153 154
        public DateTime CurrTime { get; protected set; } = DateTime.MinValue;

潘栩锋's avatar
潘栩锋 committed
155 156 157 158

        /// <summary>
        /// 当前检测出来的厚度数据,方向
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
159 160
        public Misc.DIRECTION CurrDirection { get; protected set; } = Misc.DIRECTION.FORWARD;

潘栩锋's avatar
潘栩锋 committed
161 162 163 164

        #endregion

        #region 列表
潘栩锋's avatar
潘栩锋 committed
165

潘栩锋's avatar
潘栩锋 committed
166 167 168
        /// <summary>
        /// 列表最后1个BM
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
169 170
        public int LastBM { get; protected set; }

潘栩锋's avatar
潘栩锋 committed
171 172 173 174

        /// <summary>
        /// 列表第1个BM
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
175 176
        public int FirstBM { get; protected set; }

潘栩锋's avatar
潘栩锋 committed
177 178 179
        #endregion

        #region 每个分区状态
潘栩锋's avatar
潘栩锋 committed
180 181 182 183

        [PropertyChanged.DoNotCheckEquality]
        public bool[] BoltIsStable { get; protected set; }

潘栩锋's avatar
潘栩锋 committed
184 185 186 187 188 189
        #endregion
        #endregion


        #endregion

190 191
        public HeatBufServiceClient(UInt32 serviceId) : base(serviceId) { }
        public HeatBufServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
潘栩锋's avatar
潘栩锋 committed
192 193 194 195

        #region IFObj
        public override void ConnectNotify(IFConn from)
        {
196
            base.ConnectNotify(from);
潘栩锋's avatar
潘栩锋 committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
            if (from.IsConnected)
            {

                FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.GET_PARAMS);
                FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.GET_STATE);

                FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.GET_BM);
                FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.GET_ISSTABLES);
                FObjSys.Current.SenseConfigEx(mConn, mServerID, ID, 0xffffffff, SENSE_CONFIG.ADD);
            }
        }

        public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case HEATBUF_OBJ_INTERFACE.GET_PARAMS:
                    {
潘栩锋's avatar
潘栩锋 committed
215 216 217 218
                        string json = Misc.Converter.BytesToString(infodata);

                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATBUF_OBJ_INTERFACE.Pack_Params>(json);

潘栩锋's avatar
潘栩锋 committed
219 220 221 222 223 224 225 226 227 228 229 230
                        HeatEffectCurve = p.HeatEffectCurve;
                        StableRange = p.StableRange;
                        StableRange0 = p.StableRange0;
                        ThresholdR = p.ThresholdR;
                        ThresholdMaxMin = p.ThresholdMaxMin;
                        ThresholdSigmaMax = p.ThresholdSigmaMax;
                        IsUsedLocalKp = p.IsUsedLocalKp;
                        LocalKp = p.LocalKp;
                    }
                    break;
                case HEATBUF_OBJ_INTERFACE.GET_STATE:
                    {
潘栩锋's avatar
潘栩锋 committed
231 232 233 234 235
                        string json = Misc.Converter.BytesToString(infodata);

                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATBUF_OBJ_INTERFACE.Pack_Status>(json);


潘栩锋's avatar
潘栩锋 committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
                        Delay = p.Delay;
                        IsIntoAutoONo = p.IsIntoAutoONo;
                        AutoONoResult = p.AutoONoResult;

                        BestOrgBoltNo = p.BestOrgBoltNo;
                        BestKp = p.BestKp;
                        MaxR = p.MaxR;
                        MaxMin = p.MaxMin;
                        Stability = p.Stability;
                        CurrR = p.CurrR;
                        Curr2Sigma = p.Curr2Sigma;
                        CurrBreakUp = p.CurrBreakUp;

                        CurrTime = p.CurrTime;
                        CurrDirection = p.CurrDirection;
                    }
                    break;

                case HEATBUF_OBJ_INTERFACE.GET_BM:
                    {
潘栩锋's avatar
潘栩锋 committed
256 257 258 259 260
                        string json = Misc.Converter.BytesToString(infodata);

                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATBUF_OBJ_INTERFACE.Pack_BM>(json);


潘栩锋's avatar
潘栩锋 committed
261 262 263 264 265 266
                        FirstBM = p.firstbm;
                        LastBM = p.lastbm;
                    }
                    break;
                case HEATBUF_OBJ_INTERFACE.GET_ISSTABLES:
                    {
潘栩锋's avatar
潘栩锋 committed
267 268 269 270
                        string json = Misc.Converter.BytesToString(infodata);

                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATBUF_OBJ_INTERFACE.Pack_IsStables>(json);

潘栩锋's avatar
潘栩锋 committed
271 272 273 274 275 276 277 278 279 280 281
                        BoltIsStable = p.isStables;
                    }
                    break;
            }
        }
        public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
        {
            switch (funcid)
            {
                case HEATBUF_OBJ_INTERFACE.CALL_GETHEATDATA:
                    {
潘栩锋's avatar
潘栩锋 committed
282 283 284 285
                        string json = Misc.Converter.BytesToString(retdata);
                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<FlyData_FeedbackHeat>(json);
                        ((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
                        
潘栩锋's avatar
潘栩锋 committed
286 287 288 289
                    }
                    break;
                case HEATBUF_OBJ_INTERFACE.CALL_GETBOLTHEATRECORD:
                    {
潘栩锋's avatar
潘栩锋 committed
290 291 292
                        string json = Misc.Converter.BytesToString(retdata);
                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<FlyData_BoltHeatRecord>(json);
                        ((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
潘栩锋's avatar
潘栩锋 committed
293 294 295 296 297 298 299 300 301
                    }
                    break;

            }
        }
        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {
            PushGetValue(from, srcid, infoid, infodata);
        }
302

潘栩锋's avatar
潘栩锋 committed
303 304 305 306
        #endregion

        public void Apply()
        {
潘栩锋's avatar
潘栩锋 committed
307 308 309 310 311 312 313 314 315 316 317 318 319
            var p = new HEATBUF_OBJ_INTERFACE.Pack_Params()
            {
                HeatEffectCurve = HeatEffectCurve,
                StableRange = StableRange,
                StableRange0 = StableRange0,
                ThresholdR = ThresholdR,
                ThresholdMaxMin = ThresholdMaxMin,
                ThresholdSigmaMax = ThresholdSigmaMax,
                IsUsedLocalKp = IsUsedLocalKp,
                LocalKp = LocalKp
            };
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);

潘栩锋's avatar
潘栩锋 committed
320 321 322
            FObjSys.Current.SetValueEx(
              mConn, mServerID, ID,
              HEATBUF_OBJ_INTERFACE.SET_PARAMS,
潘栩锋's avatar
潘栩锋 committed
323
              Misc.Converter.StringToBytes(json));
潘栩锋's avatar
潘栩锋 committed
324 325 326 327

        }
        public void GetHeatsData(int bookmark, AsyncCBHandler AsyncDelegate, object AsyncState)
        {
潘栩锋's avatar
潘栩锋 committed
328 329 330
            var p = new HEATBUF_OBJ_INTERFACE.Pack_GetHeatsDataRequest() { bookmark = bookmark };
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);

潘栩锋's avatar
潘栩锋 committed
331 332
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                HEATBUF_OBJ_INTERFACE.CALL_GETHEATDATA,
潘栩锋's avatar
潘栩锋 committed
333
                Misc.Converter.StringToBytes(json),
潘栩锋's avatar
潘栩锋 committed
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
                AsyncDelegate, AsyncState);
        }
        public void ClearBoltHeat()
        {
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                HEATBUF_OBJ_INTERFACE.CALL_CLEARBOLTHEAT,
                null);
        }

        /// <summary>
        /// 获取每个分区的加热历史 返回 FlyData_BoltHeatRecord
        /// </summary>
        /// <param name="no">分区号</param>
        /// <param name="AsyncDelegate"></param>
        /// <param name="AsyncState"></param>
        public void GetBoltHeatRecord(int no, AsyncCBHandler AsyncDelegate, object AsyncState)
        {
潘栩锋's avatar
潘栩锋 committed
351 352 353
            var p = new HEATBUF_OBJ_INTERFACE.Pack_GetBoltHeatRecordRequest() { no = no };
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);

潘栩锋's avatar
潘栩锋 committed
354 355
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                HEATBUF_OBJ_INTERFACE.CALL_GETBOLTHEATRECORD,
潘栩锋's avatar
潘栩锋 committed
356
                Misc.Converter.StringToBytes(json),
潘栩锋's avatar
潘栩锋 committed
357 358 359 360 361
                AsyncDelegate, AsyncState);
        }

    }
}