CalFilmLen.cs 26.2 KB
Newer Older
1 2
using FLY.Thick.Base.IService;
using FLY.Thick.Blowing.IService;
3
using FLY.Thick.Blowing.UI;
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 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
using FLY.Thick.BlowingScan.Common;
using FLY.Thick.BlowingScan.IService;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace FLY.Thick.BlowingScan.UI.Client
{
    public class CalFilmLen : INotifyPropertyChanged
    {

        #region 状态
        /// <summary>
        /// 信息
        /// </summary>
        public string Msg { get; protected set; }

        /// <summary>
        /// 下载中
        /// </summary>
        public bool IsDownloading { get; protected set; }
        /// <summary>
        /// 数据准备好了
        /// </summary>
        public bool IsDataReady { get; protected set; }

        /// <summary>
        /// 有足够的数据,可以下载
        /// </summary>
        public bool IsCanDownload { get; protected set; }

        /// <summary>
        /// 数据总量
        /// </summary>
        public TimeSpan BufTotalTime { get; protected set; }

        /// <summary>
        /// 当前正在下载的数据序号
        /// </summary>
        public int BufListDownloadNo { get; protected set; }

        /// <summary>
        /// 最后目标下载的数据序号
        /// </summary>
        public int BufListDownloadEndNo { get; protected set; }
        /// <summary>
        /// 下载数据 添加到当前的数据队列后面
        /// </summary>
        public bool IsBufListAdd { get; protected set; }
        #endregion

        #region 参数
        public bool Is3D { get; protected set; }
        public bool IsRPosMode { get; protected set; }
        /// <summary>
        /// 第1牵引速度
        /// </summary>
        public double Velocity1 { get; protected set; }

        /// <summary>
        /// 速度滤波 单位s
        /// </summary>
        public int VelocityFilter { get; protected set; } = 1;

        #endregion

        IBlowingScanService mRenZiJia;
        IBlowingDetectService mCurrRDetect;

        BlowingDetectCore mRDetectCore;
        BlowingScanAnaylze mAnaylze;

        List<LimitCell> mLimitList = new List<LimitCell>();
        List<RollCell> mRollList = new List<RollCell>();
        List<RPosData> mRPosList = new List<RPosData>();

        //下载时的数据缓存区而已
        List<FlyData_BlowingScan> bufList = new List<FlyData_BlowingScan>();
        #region 画图
        public List<TimeValue> LimitValues { get; } = new List<TimeValue>();

        public List<TimeValue> VelocityValues { get; } = new List<TimeValue>();

        public List<TimeValue> ThicknessValues { get; } = new List<TimeValue>();

        public List<TimeValue> AngleValues { get; } = new List<TimeValue>();

        public List<TimeValue> FilmLength3DValues { get; } = new List<TimeValue>();

        [PropertyChanged.DoNotCheckEquality]
        public List<double> CurrFilmLength3D { get; set; } = new List<double>();

        [PropertyChanged.DoNotCheckEquality]
        public List<double> NewFilmLength3D { get; set; } = new List<double>();


        #endregion

        DateTime dataBegin;

        public CalFilmLen()
        {
            mRDetectCore = new BlowingDetectCore();
        }

        public void Init(
            IBlowingScanService renZiJia,
            IBlowingDetectService rDetect,
            BlowingScanAnaylze blowingScanAnaylze)
        {
            this.mRenZiJia = renZiJia;
            this.mCurrRDetect = rDetect;
            this.mAnaylze = blowingScanAnaylze;

            this.mAnaylze.Init(mRDetectCore);

            Misc.BindingOperations.SetBinding(mCurrRDetect, nameof(mCurrRDetect.BufTotalTime), () =>
            {
                BufTotalTime = mCurrRDetect.BufTotalTime;
                IsCanDownload = mCurrRDetect.BufTotalTime > TimeSpan.FromMinutes(1);
            });
            
            Misc.BindingOperations.SetBinding(mCurrRDetect, nameof(mCurrRDetect.Is3D), this, nameof(Is3D));
            Misc.BindingOperations.SetBinding(mCurrRDetect, nameof(mCurrRDetect.IsRPosMode), this, nameof(IsRPosMode));

        }


        ActionQueue actionQueue = new ActionQueue();
        public bool DownloadData()
        {
            //应该在界面 检测错误原因
            if (IsDownloading)
                return false;

            dataBegin = DateTime.Now - mCurrRDetect.BufTotalTime;
            IsDownloading = true;
            IsDataReady = false;

            //按步骤下载数据
            actionQueue.Clear();

            actionQueue.Add(DownloadData_limit);
            actionQueue.Add(DownloadData_roll);

            if (IsRPosMode)
                actionQueue.Add(DownloadData_rPos);

            if (Is3D)
                actionQueue.Add(DownloadData_CurrFilmLength3D);

            actionQueue.Add(DownloadData_BufList);

            actionQueue.Add(DownloadData_OK);

            actionQueue.Start();

            return true;
        }

        public class ActionQueue
        {
            List<Action> actions = new List<Action>();
            public void Add(Action action)
            {
                actions.Add(action);
            }
            public bool Start()
            {
                return Next();
            }
            public bool Next()
            {
                if (actions.Count() > 0)
                {
                    var action = actions.First();
                    actions.RemoveAt(0);
                    action.Invoke();
                    return true;
                }
                return false;
            }

            public bool IsEmpty()
            {
                if (actions.Count() == 0)
                    return true;
                else
                    return false;
            }

            public void Clear()
            {
                actions.Clear();
            }
        }



        void DownloadData_limit()
        {
            DateTime dateTime = dataBegin;
            if (mLimitList.Count() > 0)
            {
                dateTime = mLimitList.Last().dt_begin;
                if (dateTime < dataBegin)
                {
                    //数据太久,先删除,再下载
                    mLimitList.Clear();
                    dateTime = dataBegin;
                }
            }
            Msg = $"下载 转向信号数据 ({dateTime} - Now]....";

            mCurrRDetect.GetLimitList(dateTime,
                (object asyncContext, object retData) => {
                    var p = retData as GetLimitListReponse;
                    if (p.datas != null && p.datas.Count() > 0)//有数据
                        mLimitList.AddRange(p.datas);

                    //下一步
                    actionQueue.Next();
                }, null);
        }
        void DownloadData_roll()
        {

            DateTime dateTime = dataBegin;
            if (mRollList.Count() > 0)
            {
                dateTime = mRollList.Last().Time;
                if (dateTime < dataBegin)
                {
                    //数据太久,先删除,再下载
                    mRollList.Clear();
                    dateTime = dataBegin;
                }
            }
            Msg = $"下载 辊信号数据 [{dateTime} - Now]....";

            mCurrRDetect.GetRollList(dateTime,
                (object asyncContext, object retData) => {
                    var p = retData as GetRollListReponse;
                    if (p.datas != null && p.datas.Count() > 0)
                        mRollList.AddRange(p.datas);

                    //下一步
                    actionQueue.Next();
                }, null);
        }

        void DownloadData_rPos()
        {
            DateTime dateTime = dataBegin;
            if (mRPosList.Count() > 0)
            {
                dateTime = mRPosList.Last().Time;
                if (dateTime < dataBegin)
                {
                    //数据太久,先删除,再下载
                    mRPosList.Clear();
                    dateTime = dataBegin;
                }
            }

            Msg = $"下载 旋转脉冲数据 [{dateTime} - Now]....";


            mCurrRDetect.GetRPosList(dateTime,
                (object asyncContext, object retData) => {
                    var p = retData as GetRPosListReponse;
                    if (p.datas != null && p.datas.Count() > 0)
                        mRPosList.AddRange(p.datas);

                    actionQueue.Next();
                }, null);
        }

        void DownloadData_CurrFilmLength3D()
        {
            Msg = $"下载 膜距离增量数据";
            mCurrRDetect.GetFilmLength3D(
                (object asyncContext, object retData) => {
                    var p = retData as GetFilmLength3DReponse;
                    CurrFilmLength3D = p.datas;

                    actionQueue.Next();
                }, null);
        }

        void DownloadData_BufList()
        {
            if (mRenZiJia.BufListCount == 0) 
            {
                //没有数据
                actionQueue.Next();
                return;
            }

            if (mAnaylze.mBufList.Count() > 0 && mAnaylze.BufListLastNo == mRenZiJia.BufListLastNo) 
            {
                //数据已经最新
                actionQueue.Next();
                return;
            }
            

            //下载
            int startNo = mRenZiJia.BufListLastNo - mRenZiJia.BufListCount + 1;
            int endNo = mRenZiJia.BufListLastNo;
            bool isAdd = false;

            if (mAnaylze.mBufList.Count() > 0)
            {
                //当前数据与服务器数据有交集,交集部分就不用下载了
                int count = mRenZiJia.BufListLastNo - mAnaylze.BufListLastNo;
                if (count > 0)
                {
                    //有数据多,需要下载
                    if (count < mRenZiJia.BufListCount)
                    {
                        //当前数据与服务器数据有交集,交集部分就不用下载了
                        startNo = mRenZiJia.BufListLastNo - count + 1;
                        isAdd = true;
                    }
                    else
                    {
                        //没有交集, 清空当前数据
                    }
                }
                else if (count < 0)
                {
                    //异常!!!!不可能,清空当前数据,全部数据下载
                }
            }
            else
            {
                //全部数据下载
            }
            
            BufListDownloadNo = startNo;
            BufListDownloadEndNo = endNo;
            Msg = $"下载 扫描厚度数据 {BufListDownloadNo}/{BufListDownloadEndNo}";

            IsBufListAdd = isAdd;
            bufList.Clear();

            mRenZiJia.GetBufList(BufListDownloadNo, BufListDownloaded, null);
        }
        void BufListDownloaded(object asyncContext, object retData)
        {
            GetBufListReponse reponse = retData as GetBufListReponse;
            //
            if (reponse.data != null)
                bufList.Add(reponse.data);

            if (reponse.no != BufListDownloadEndNo)
            {
                //继续努力
                BufListDownloadNo++;
                Msg = $"下载 扫描厚度数据 {BufListDownloadNo}/{BufListDownloadEndNo}";

                mRenZiJia.GetBufList(BufListDownloadNo, BufListDownloaded, null);
                return;
            }

            actionQueue.Next();
        }


        void DownloadData_OK()
        {
            Msg = "数据下载完成";
            IsDownloading = false;
            IsDataReady = true;

            //把下载的数据,都放入 旋转模拟器
            mRDetectCore.Init(
                mCurrRDetect.RAngle,
                mCurrRDetect.RollPerimeter,
                mCurrRDetect.RenZiJiaPeriod,
                mCurrRDetect.FilmLength,
                Is3D,
                mRollList,
                mLimitList,
                CurrFilmLength3D,
                mCurrRDetect.DefaultTime,
                IsRPosMode,
                mCurrRDetect.OrgRPos,
                mCurrRDetect.RPosOfR,
                mRPosList);

            UpdateLimitValues();
            UpdateVelocityValues(VelocityFilter);
            if (mCurrRDetect.IsRPosMode)
            {
                UpdateAngleValues();
            }

            //第1步
            mAnaylze.Step1(BufListDownloadEndNo, bufList, IsBufListAdd);
            bufList.Clear();

            UpdateThicknessValues();

            //第2步,修改 旋转角度,膜距离 执行 解方程
            Thread t = new Thread(mAnaylze.Step2);
            t.IsBackground = true;
            t.Start();
        }

        /// <summary>
        /// 更新平滑后的速度曲线
        /// </summary>
        /// <param name="velocity_filter"></param>
        public void UpdateVelocityValues(int velocity_filter)
        {
            VelocityFilter = velocity_filter;
            var filter_half = TimeSpan.FromSeconds(VelocityFilter / 2);

            VelocityValues.Clear();

            for (int i = 0; i < mRollList.Count(); i++)
            {
                //寻找 滤波时间 为半径 前后数据点
                var dt_min = mRollList[i].Time - filter_half;
                var dt_max = mRollList[i].Time + filter_half;

                int i_begin = 0;
                int i_end = mRollList.Count() - 1;

                for (int j = i; j >= 0; j--)
                {
                    if (mRollList[j].Time <= dt_min)
                    {
                        //找到了 
                        i_begin = j;
                        break;
                    }
                }

                for (int j = i; j < mRollList.Count(); j++)
                {
                    if (mRollList[j].Time >= dt_max)
                    {
                        //找到了 
                        i_end = j;
                        break;
                    }
                }

                if (i_begin == i_end)
                {
                    i_begin = i;
                    i_end = i + 1;
                    if (i_end >= mRollList.Count())
                    {
                        i_begin = i - 1;
                        i_end = i;
                    }
                }


                TimeSpan ts = mRollList[i_end].SysTime - mRollList[i_begin].SysTime;
                double minute = 1.0 * ts.Ticks / TimeSpan.TicksPerMinute;
                double v = (i_end - i_begin) * mCurrRDetect.RollPerimeter / 1000 / minute;
                VelocityValues.Add(
                    new TimeValue()
                    {
                        Time = mRollList[i].Time,
                        Value = v
                    });
            }
            OnPropertyChanged(nameof(VelocityValues));

            //算出速度平均值
            Velocity1 = VelocityValues.Average(tv => tv.Value);
            if (Is3D)
                UpdateFilmLength3D(Velocity1);//对速度的与Velocity1的偏差,算出积分,那就是膜距离的增量

        }
        /// <summary>
        /// //对速度的与Velocity1的偏差,算出积分,那就是膜距离的增量
        /// </summary>
        /// <param name="velocity1"></param>
        public void UpdateFilmLength3D(double velocity1)
        {
            Velocity1 = velocity1;

            FilmLength3DValues.Clear();
            double sum = 0;
            FilmLength3DValues.Add(
                new TimeValue()
                {
                    Time = VelocityValues[0].Time,
                    Value = sum
                });
            for (int i = 1; i < VelocityValues.Count(); i++)
            {
                var ts = VelocityValues[i].Time - VelocityValues[i - 1].Time;
                double minute = 1.0 * ts.Ticks / TimeSpan.TicksPerMinute;
                double velocity2 = (VelocityValues[i].Value + VelocityValues[i - 1].Value) / 2;

                //2牵引 比 1牵引 快, 膜距离就会越来越短
                //1牵引 比 2牵引 快, 膜距离就会越来越长

                sum += (Velocity1 - velocity2) * minute;
                FilmLength3DValues.Add(
                    new TimeValue()
                    {
                        Time = VelocityValues[i].Time,
                        Value = sum
                    });
            }
            //对数据平移, 使均值为0
            double avg_f = FilmLength3DValues.Average(tv => tv.Value);
            foreach (var tv in FilmLength3DValues)
                tv.Value -= avg_f;

            OnPropertyChanged(nameof(FilmLength3DValues));

            UpdateNewFilmLength3D();
        }
        void UpdateThicknessValues()
        {
            ThicknessValues.Clear();

            foreach (var scanInfoCell in mAnaylze.ScanInfoList)
            {
                ThicknessValues.Add(
                    new TimeValue()
                    {
                        Time = scanInfoCell.StartTime,
                        Value = scanInfoCell.Avg
                    });
            }
            OnPropertyChanged(nameof(ThicknessValues));
        }
        void UpdateLimitValues()
        {
            LimitValues.Clear();

            foreach (var limit in mLimitList)
            {
                DateTime dt = limit.dt_begin;
                if (dt == DateTime.MinValue)
                    dt = limit.dt_end;

                LimitValues.Add(new TimeValue() { Time = dt, Value = limit.no });
            }
            
            OnPropertyChanged(nameof(LimitValues));
        }

        /// <summary>
        /// 通过旋转脉冲算出旋转角度曲线
        /// </summary>
        void UpdateAngleValues()
        {
            AngleValues.Clear();
            foreach (var rPosData in mRPosList)
            {
                var angle = mRDetectCore.GetAngleByGlobalRPos(rPosData.GlobalRPos);
                AngleValues.Add(new TimeValue() { Time = rPosData.Time, Value = angle });
            }
            
            OnPropertyChanged(nameof(AngleValues));
        }



        void UpdateNewFilmLength3D()
        {
            int n = 360;
            double[] sum = new double[n];
            int[] cnt = new int[n];

            for (int i = 0; i < FilmLength3DValues.Count(); i++)
            {
                var filmlength3d = FilmLength3DValues[i];
                //通过时间找角度
                bool ret = mRDetectCore.GetAngle(filmlength3d.Time, false, out double angle, out Misc.DIRECTION direction, out int rotationCnt, out bool inCV);
                if (ret)
                {
                    angle += 180;
                    int index = (int)angle;
                    if (index >= 0 && index < n)
                    {
                        sum[index] += filmlength3d.Value;
                        cnt[index]++;
                    }
                }
            }

            //求均值
            for (int i = 0; i < n; i++)
            {
                if (cnt[i] > 0)
                    sum[i] = sum[i] / cnt[i];
            }

            //把两边空的部分补齐
            for (int i = n / 2; i >= 0; i--)
            {
                if (cnt[i] == 0)
                {
                    sum[i] = sum[i + 1];
                }
            }
            for (int i = n / 2; i < n; i++)
            {
                if (cnt[i] == 0)
                {
                    sum[i] = sum[i - 1];
                }
            }

            NewFilmLength3D = sum.ToList();
        }
        public void SetFilmLength3D()
        {
            CurrFilmLength3D = NewFilmLength3D;
            mRDetectCore.mFilmLength3D = CurrFilmLength3D;

            //TODO
            //mAnaylze.


            mCurrRDetect.SetFilmLength3D(CurrFilmLength3D);
            FLY.ControlLibrary.Window_Tip.Show(
                "应用成功",
                $"立体式旋转 膜距离增量设置成功",
                TimeSpan.FromSeconds(2));
        }
        public void ClearFilmLength3D()
        {
            CurrFilmLength3D = null;
            mRDetectCore.mFilmLength3D = CurrFilmLength3D;

            //TODO

            mCurrRDetect.SetFilmLength3D(CurrFilmLength3D);
            FLY.ControlLibrary.Window_Tip.Show(
                "删除成功",
                $"立体式旋转 膜距离增量删除成功",
                TimeSpan.FromSeconds(2));
        }

        public event PropertyChangedEventHandler PropertyChanged;



        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        //string file_path = "bulkdb.json";
        public void Save(string file_path)
        {
            try
            {
                CalFilmLenJsonDb param = new CalFilmLenJsonDb()
                {
                    RAngle = mRDetectCore.RAngle,
                    RollPerimeter = mRDetectCore.RollPerimeter,
                    RenZiJiaPeriod = mRDetectCore.RenZiJiaPeriod,
                    FilmLength = mRDetectCore.FilmLength,
                    Is3D = mRDetectCore.Is3D,
                    mRollList = mRDetectCore.mRollList.Select(r=>new RollCell() { Time = r.Time, SysTime = r.SysTime }).ToList(),
                    mLimitList = mRDetectCore.mLimitList,
                    mFilmLength3D = mRDetectCore.mFilmLength3D,
                    DefaultTime = mRDetectCore.DefaultTime,
                    IsRPosMode = mRDetectCore.IsRPosMode,
                    mRPosList = mRDetectCore.mRPosList,
                    RPosOfR = mRDetectCore.RPosOfR,
                    OrgRPos = mRDetectCore.OrgRPos,

                    
                    NBolts = mAnaylze.NBolts,
                    OrgBoltNo = mAnaylze.OrgBoltNo,
                    mBufList = mAnaylze.mBufList,
                    SolveCnt = mAnaylze.SolveCnt,
                    SensorWidth = mAnaylze.Sensor,
                    N2 = mAnaylze.N2,
                    Smooth = mAnaylze.Smooth
                };

                File.WriteAllText(file_path, JsonConvert.SerializeObject(param, Formatting.Indented));
            }
            catch
            {
                //异常,没有json 编码失败

            }
        }
        public void Load(string file_path)
        {
            try
            {
                if (File.Exists(file_path))
                {
                    string json = File.ReadAllText(file_path);

                    var param = JsonConvert.DeserializeObject<CalFilmLenJsonDb>(json);
                    Load(param);
                }
            }
            catch
            {
                //异常,没有json 解码失败

            }
        }

        void Load(CalFilmLenJsonDb param)
        {

            mLimitList.Clear();
            mRPosList.Clear();
            mRollList.Clear();

            mLimitList.AddRange(param.mLimitList);
            mRPosList.AddRange(param.mRPosList);
            mRollList.AddRange(param.mRollList);

            CurrFilmLength3D = param.mFilmLength3D;

            Is3D = param.Is3D;
            IsRPosMode = param.IsRPosMode;

            //把下载的数据,都放入 旋转模拟器
            mRDetectCore.Init(
                param.RAngle,
                param.RollPerimeter,
                param.RenZiJiaPeriod,
                param.FilmLength,
                param.Is3D,
                param.mRollList,
                param.mLimitList,
                param.mFilmLength3D,
                param.DefaultTime,
                param.IsRPosMode,
                param.OrgRPos,
                param.RPosOfR,
                param.mRPosList);

            UpdateLimitValues();
            UpdateVelocityValues(VelocityFilter);
            if (param.IsRPosMode)
            {
                UpdateAngleValues();
            }
            mAnaylze.NBolts = param.NBolts;
            
            if (mAnaylze.OrgBoltNo < 1)
                mAnaylze.OrgBoltNo = 1;
            else if (mAnaylze.OrgBoltNo > mAnaylze.NBolts)
            {
                mAnaylze.OrgBoltNo = mAnaylze.NBolts;
            }
            mAnaylze.SolveCnt = param.SolveCnt;
            mAnaylze.RAngle = param.RAngle;
            mAnaylze.FilmLength = param.FilmLength;
            mAnaylze.Sensor = param.SensorWidth;
            mAnaylze.N2 = param.N2;
            mAnaylze.Smooth = param.Smooth;

            //第1步
            mAnaylze.Step1(param.mBufList.Count(), param.mBufList, false);


            UpdateThicknessValues();

            //第2步,修改 旋转角度,膜距离 执行 解方程
            Thread t = new Thread(mAnaylze.Step2);
            t.IsBackground = true;
            t.Start();

            IsDataReady = true;
        }

    }

    public class CalFilmLenJsonDb
    {
        /// <summary>
        /// 离开限位 到 撞下一个限位 的 旋转架转动总角度 单位°
        /// </summary>
        public double RAngle;
        /// <summary>
        /// 辊周长,单位mm
        /// </summary>
        public double RollPerimeter;
        /// <summary>
        /// 离开限位 到 撞下一个限位  的 旋转架转动时间, 需要初始值,以后测量出来的
        /// </summary>
        public TimeSpan RenZiJiaPeriod;
        /// <summary>
        /// 人字架到测厚仪膜长 单位m
        /// </summary>
        public double FilmLength;

        /// <summary>
        /// 旋转架为立式,测厚仪安装在二牵引前面,膜距离 与 旋转角度 一起变化, 旋转角度越大 膜距离越大
        /// </summary>
        public bool Is3D;

        /// <summary>
        /// 辊信号列表
        /// </summary>
        public List<RollCell> mRollList;

        /// <summary>
        /// 转向信号列表
        /// </summary>
        public List<LimitCell> mLimitList;

        /// <summary>
        /// 当为 立式旋转架时,膜距离与旋转角度有关系
        /// 列表的长度为 200, 列表的头为信号0离开, 尾为信号1进入
        /// </summary>
        public List<double> mFilmLength3D;



        public DateTime DefaultTime;
        public bool IsRPosMode;
        public int OrgRPos;
        public int RPosOfR;
        public List<RPosData> mRPosList;



        public int NBolts;
        public int OrgBoltNo = 1;

        public List<FlyData_BlowingScan> mBufList;
        public int SolveCnt;
        public int SensorWidth;
        public int N2;
        public int Smooth;
    }
}