HeatBufServiceClient.cs 19.6 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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
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
{
    public class HeatBufServiceClient : FObj, IHeatBuf
    {
        IFConn mConn;
        UInt32 mServerID;


        #region 属性,对外接口
        #region 参数
        private List<int> heatEffectCurve = new List<int>();
        /// <summary>
        /// 加热生效曲线,允许为空,则不生效
        /// </summary>
        public List<int> HeatEffectCurve
        {
            get
            {
                return heatEffectCurve;
            }
            set
            {
                heatEffectCurve = value;
                NotifyPropertyChanged("HeatEffectCurve");
            }
        }

        private int stablerange = 2;
        /// <summary>
        /// 厚度稳定范围 %, 偏差在范围内,都是稳定的 
        /// </summary>
        public int StableRange
        {
            get { return stablerange; }
            set
            {
                if (stablerange != value)
                {
                    stablerange = value;
                    NotifyPropertyChanged("StableRange");
                }
            }
        }

        private int stablerange0 = 2;
        /// <summary>
        /// 厚度稳定范围 %, 加热量变化为0时,偏差在范围内,都是稳定的 
        /// </summary>
        public int StableRange0
        {
            get { return stablerange0; }
            set
            {
                if (stablerange0 != value)
                {
                    stablerange0 = value;
                    NotifyPropertyChanged("StableRange0");
                }
            }
        }

        private double thresholdR = 0.7;
        /// <summary>
        /// 对位模式, 加热与厚度相关性阀值, 相关性 >=0.7
        /// </summary>
        public double ThresholdR
        {
            get { return thresholdR; }
            set
            {
                if (thresholdR != value)
                {
                    thresholdR = value;
                    NotifyPropertyChanged("ThresholdR");
                }
            }
        }

        private int thresholdMaxMin = 8;
        /// <summary>
        /// 对位模式 厚度%差 的极差 >= +4%-4%=8%, 单位%
        /// </summary>
        public int ThresholdMaxMin
        {
            get { return thresholdMaxMin; }
            set
            {
                if (thresholdMaxMin != value)
                {
                    thresholdMaxMin = value;
                    NotifyPropertyChanged("ThresholdMaxMin");
                }
            }
        }

        private int thresholdSigmaMax = 20;
        /// <summary>
        /// %
        /// 最大sigma, 只有当前的sigma  在 最大sigma 与 最小 sigma 内,才能控制
        /// </summary>
        public int ThresholdSigmaMax
        {
            get { return thresholdSigmaMax; }
            set
            {
                if (thresholdSigmaMax != value)
                {
                    thresholdSigmaMax = value;
                    NotifyPropertyChanged("ThresholdSigmaMax");
                }
            }
        }

        private double thresholdSigmaMin = 2;
        /// <summary>
        /// %
        /// 最小sigma, 只有当前的sigma  在 最大sigma 与 最小 sigma 内,才能控制
        /// </summary>
        public double ThresholdSigmaMin
        {
            get { return thresholdSigmaMin; }
            set
            {
                if (thresholdSigmaMin != value)
                {
                    thresholdSigmaMin = value;
                    NotifyPropertyChanged("ThresholdSigmaMin");
                }
            }
        }


        private bool isUsedKp = false;
        /// <summary>
        /// 使用这里独立的Kp, 与 HeatCell 不一样
        /// </summary>
        public bool IsUsedLocalKp
        {
            get { return isUsedKp; }
            set
            {
                if (isUsedKp != value)
                {
                    isUsedKp = value;
                    NotifyPropertyChanged("IsUsedLocalKp");
                }
            }
        }

        private double localkp = 3;
        /// <summary>
        /// 本地Kp, 用于判断稳定性
        /// </summary>
        public double LocalKp
        {
            get { return localkp; }
            set
            {
                if (localkp != value)
                {
                    localkp = value;
                    NotifyPropertyChanged("LocalKp");
                }
            }
        }
        #endregion

        #region 状态

        private TimeSpan delay = TimeSpan.FromSeconds(100);
        /// <summary>
        /// 总延时 =Delay+mRenZiJiaService.FilmLength/mRenZiJiaService.Velocity
        /// </summary>
        public TimeSpan Delay
        {
            get { return delay; }
            set
            {
                if (delay != value)
                {
                    delay = value;
                    NotifyPropertyChanged("Delay");
                }
            }
        }

        #region 对位
        private bool isIntoAutoONo = false;
        /// <summary>
        /// 进入了对位模式
        /// </summary>
        public bool IsIntoAutoONo
        {
            get { return isIntoAutoONo; }
            set
            {
                if (isIntoAutoONo != value)
                {
                    isIntoAutoONo = value;
                    NotifyPropertyChanged("IsIntoAutoONo");
                }
            }
        }

        private EAutoONoResult autoONoResult = EAutoONoResult.Idle;
        /// <summary>
        /// 对位模式结果
        /// </summary>
        public EAutoONoResult AutoONoResult
        {
            get { return autoONoResult; }
            set
            {
                if (autoONoResult != value)
                {
                    autoONoResult = value;
                    NotifyPropertyChanged("AutoONoResult");
                }
            }
        }

        private int bestOrgBoltNo = -1;
        /// <summary>
        /// 计算的最佳复位区号
        /// </summary>
        public int BestOrgBoltNo
        {
            get { return bestOrgBoltNo; }
            set
            {
                if (bestOrgBoltNo != value)
                {
                    bestOrgBoltNo = value;
                    NotifyPropertyChanged("BestOrgBoltNo");
                }
            }
        }

        private double bestkp = -1;
        /// <summary>
        /// 计算的最佳复位区号 对应的 加热/厚度 
        /// </summary>
        public double BestKp
        {
            get { return bestkp; }
            set
            {
                if (bestkp != value)
                {
                    bestkp = value;
                    NotifyPropertyChanged("BestKp");
                }
            }
        }

        private double maxR = -1;
        /// <summary>
        /// 计算的最佳复位区号 对应的 加热与厚度相关性
        /// </summary>
        public double MaxR
        {
            get { return maxR; }
            set
            {
                if (maxR != value)
                {
                    maxR = value;
                    NotifyPropertyChanged("MaxR");
                }
            }
        }

        private double maxmin = -1;
        /// <summary>
        /// 计算的最佳复位区号 对应的 厚度%变化极差 单位%
        /// </summary>
        public double MaxMin
        {
            get { return maxmin; }
            set
            {
                if (maxmin != value)
                {
                    maxmin = value;
                    NotifyPropertyChanged("MaxMin");
                }
            }
        }
        #endregion

        #region 稳定性
        private STABILITY stability = STABILITY.IDLE;
        /// <summary>
        /// 当前检测出来的厚度数据 稳定状态
        /// </summary>
        public STABILITY Stability
        {
            get { return stability; }
            protected set
            {
                if (stability != value)
                {
                    stability = value;
                    NotifyPropertyChanged("Stability");
                }
            }
        }

        private double currR = -1;
        /// <summary>
        /// 当前检测出来的厚度数据 的稳定性 
        /// </summary>
        public double CurrR
        {
            get { return currR; }
            protected set
            {
                if (currR != value)
                {
                    currR = value;
                    NotifyPropertyChanged("CurrR");
                }
            }
        }

        private double curr2Sigma = -1;
        /// <summary>
        /// 当前检测出来的厚度数据 2Sigma
        /// </summary>
        public double Curr2Sigma
        {
            get
            {
                return curr2Sigma;
            }
            protected set
            {
                if (curr2Sigma != value)
                {
                    curr2Sigma = value;
                    NotifyPropertyChanged("Curr2Sigma");
                }
            }
        }
        private double currBreakUp = 50;
        /// <summary>
        /// 当前打散程度。 
        /// 连续N点都在平均值同一侧为一个块;
        /// 这些块的长度平均值/总长度, 为打散度;
        /// 打散度越小越好, 最小为 1/NBolts
        /// </summary>
        public double CurrBreakUp
        {
            get
            {
                return currBreakUp;
            }
            protected set
            {
                if (currBreakUp != value)
                {
                    currBreakUp = value;
                    NotifyPropertyChanged("CurrBreakUp");
                }
            }
        }
        DateTime currtime = DateTime.MinValue;
        /// <summary>
        /// 当前检测出来的厚度数据,时间
        /// </summary>
        public DateTime CurrTime
        {
            get
            {
                return currtime;
            }
            protected set
            {
                if (currtime != value)
                {
                    currtime = value;
                    NotifyPropertyChanged("CurrTime");
                }
            }
        }

        private Misc.DIRECTION currDirection = Misc.DIRECTION.FORWARD;
        /// <summary>
        /// 当前检测出来的厚度数据,方向
        /// </summary>
        public Misc.DIRECTION CurrDirection
        {
            get { return currDirection; }
            protected set
            {
                if (currDirection != value)
                {
                    currDirection = value;
                    NotifyPropertyChanged("CurrDirection ");
                }
            }
        }

        #endregion

        #region 列表
        private int lastbm = 0;
        /// <summary>
        /// 列表最后1个BM
        /// </summary>
        public int LastBM
        {
            get { return lastbm; }
            protected set
            {
                if (lastbm != value)
                {
                    lastbm = value;
                    NotifyPropertyChanged("LastBM");
                }
            }
        }

        private int firstbm = 0;
        /// <summary>
        /// 列表第1个BM
        /// </summary>
        public int FirstBM
        {
            get { return firstbm; }
            protected set
            {
                if (firstbm != value)
                {
                    firstbm = value;
                    NotifyPropertyChanged("FirstBM");
                }
            }
        }
        #endregion

        #region 每个分区状态
        private bool[] boltIsStable;
        public bool[] BoltIsStable
        {
            get { return boltIsStable; }
            protected set
            {
                boltIsStable = value;
                NotifyPropertyChanged("BoltIsStable");
            }
        }
        #endregion
        #endregion


        #endregion

        public HeatBufServiceClient()
        {
            mServerID = OBJ_INTERFACE_ID.HEATBUF_ID;
        }

        #region IFObj
        public override void ConnectNotify(IFConn from)
        {
            mConn = from;

            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:
                    {
                        HEATBUF_OBJ_INTERFACE.Pack_Params p = new HEATBUF_OBJ_INTERFACE.Pack_Params();
                        if (!p.TryParse(infodata))
                            return;
                        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:
                    {
                        HEATBUF_OBJ_INTERFACE.Pack_Status p = new HEATBUF_OBJ_INTERFACE.Pack_Status();
                        if (!p.TryParse(infodata))
                            return;
                        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:
                    {
                        HEATBUF_OBJ_INTERFACE.Pack_BM p = new HEATBUF_OBJ_INTERFACE.Pack_BM();
                        if (!p.TryParse(infodata))
                            return;
                        FirstBM = p.firstbm;
                        LastBM = p.lastbm;
                    }
                    break;
                case HEATBUF_OBJ_INTERFACE.GET_ISSTABLES:
                    {
                        HEATBUF_OBJ_INTERFACE.Pack_IsStables p = new HEATBUF_OBJ_INTERFACE.Pack_IsStables();
                        if (!p.TryParse(infodata))
                            return;
                        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:
                    {
                        //TODO
                        if (retdata == null)
                        {
                            ((AsyncCBHandler)AsyncDelegate)(AsyncState, null);
                        }
                        else
                        {
                            FlyData_FeedbackHeat p = new FlyData_FeedbackHeat();
                            if (!p.TryParse(retdata))
                                return;
                            ((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
                        }
                    }
                    break;
                case HEATBUF_OBJ_INTERFACE.CALL_GETBOLTHEATRECORD:
                    {
                        if (retdata == null)
                        {
                            ((AsyncCBHandler)AsyncDelegate)(AsyncState, null);
                        }
                        else
                        {
                            FlyData_BoltHeatRecord p = new FlyData_BoltHeatRecord();
                            if (!p.TryParse(retdata))
                                return;
                            ((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
                        }
                    }
                    break;

            }
        }
        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {
            PushGetValue(from, srcid, infoid, infodata);
        }
        public override void Dispose()
        {
            FObjSys.Current.SenseConfigEx(mConn, mServerID, ID, 0xffffffff, SENSE_CONFIG.REMOVE);
            base.Dispose();
        }
        #endregion

        public void Apply()
        {
            FObjSys.Current.SetValueEx(
              mConn, mServerID, ID,
              HEATBUF_OBJ_INTERFACE.SET_PARAMS,
              new HEATBUF_OBJ_INTERFACE.Pack_Params()
              {
                  HeatEffectCurve = HeatEffectCurve,
                  StableRange = StableRange,
                  StableRange0 = StableRange0,
                  ThresholdR = ThresholdR,
                  ThresholdMaxMin = ThresholdMaxMin,
                  ThresholdSigmaMax = ThresholdSigmaMax,
                  IsUsedLocalKp = IsUsedLocalKp,
                  LocalKp = LocalKp
              }.ToBytes());

        }
        public void GetHeatsData(int bookmark, AsyncCBHandler AsyncDelegate, object AsyncState)
        {
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                HEATBUF_OBJ_INTERFACE.CALL_GETHEATDATA,
                new HEATBUF_OBJ_INTERFACE.Pack_GetHeatsDataRequest() { bookmark = bookmark }.ToBytes(),
                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)
        {
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                HEATBUF_OBJ_INTERFACE.CALL_GETBOLTHEATRECORD,
                new HEATBUF_OBJ_INTERFACE.Pack_GetBoltHeatRecordRequest() { no = no }.ToBytes(),
                AsyncDelegate, AsyncState);
        }
        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyname)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
            }
        }


        #endregion
    }
}