GM_Fix.cs 2.74 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel;

using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
潘栩锋's avatar
潘栩锋 committed
10
using Misc;
11 12
using FlyADBase;
using FObjBase;
潘栩锋's avatar
潘栩锋 committed
13 14 15 16 17 18 19 20 21 22

namespace FLY.Thick.Base.Server
{
    public class GM_Fix : IGageMode, IFixService
    {
        #region IGageMode
        public CTRL_STATE GMState
        {
            get { return CTRL_STATE.FIX; }
        }
潘栩锋's avatar
潘栩锋 committed
23 24 25

        public bool IsRunning { get; protected set; }

潘栩锋's avatar
潘栩锋 committed
26
        #endregion
27 28 29 30 31

        #region IFixService
        public DateTime UpdateTime { get; private set; }
        #endregion

32 33 34 35
        /// <summary>
        /// 闲置时(IsRunning==false) 忽略数据
        /// </summary>
        public bool IsIgnoreDataWhenIdle { get; set; } = true;
36 37 38
        FlyADBase.FlyAD7 mFlyAD;
        DynArea mDynArea;
        AD2ThkHandler Ad2Thk;
39
        GetFixDatasReponse reponse;
40
        public GM_Fix() 
潘栩锋's avatar
潘栩锋 committed
41
        {
42 43
            
            
潘栩锋's avatar
潘栩锋 committed
44
        }
45
        public void Init(FlyADBase.FlyAD7 flyad, DynArea dynarea, AD2ThkHandler func_ad2thk)
潘栩锋's avatar
潘栩锋 committed
46
        {
47
            mFlyAD = flyad;
潘栩锋's avatar
潘栩锋 committed
48 49 50

            mDynArea = dynarea;

51 52 53
            Ad2Thk = func_ad2thk;

            flyad.TimeGridEvent += new FlyADBase.TimeGridEventHandler(flyad_TimeGridEvent);
潘栩锋's avatar
潘栩锋 committed
54 55
        }
        /// <summary>
潘栩锋's avatar
潘栩锋 committed
56
        /// 1s 的AD值,就只是用来显示到主界面左上面角而已 DynArea.AD
潘栩锋's avatar
潘栩锋 committed
57 58
        /// </summary>
        List<int> Data1s = new List<int>();
59
        
潘栩锋's avatar
潘栩锋 committed
60 61 62 63 64

        void flyad_TimeGridEvent(object sender, FlyADBase.TimeGridEventArgs e)
        {
            DateTime dt = e.Time;
            TimeSpan ts = e.Ts;
65
            var datas = e.Data.ToArray();
潘栩锋's avatar
潘栩锋 committed
66

67
            //1秒数据, 大概而已
68
            Data1s.AddRange(datas);
潘栩锋's avatar
潘栩锋 committed
69
            if (TimeSpan.FromTicks(Data1s.Count * ts.Ticks) >= TimeSpan.FromSeconds(1)) 
潘栩锋's avatar
潘栩锋 committed
70
            {
潘栩锋's avatar
潘栩锋 committed
71
                int ad = (int)Data1s.Average();
潘栩锋's avatar
潘栩锋 committed
72 73 74
                Data1s.Clear();

                mDynArea.AD = ad;
潘栩锋's avatar
潘栩锋 committed
75
                mDynArea.Thk = Ad2Thk(ad);
潘栩锋's avatar
潘栩锋 committed
76
            }
潘栩锋's avatar
潘栩锋 committed
77 78


潘栩锋's avatar
潘栩锋 committed
79
            //转换为thick
80
            double[] thks = datas.Select((ad) => Ad2Thk(ad)).ToArray();
潘栩锋's avatar
潘栩锋 committed
81

82
            reponse = new GetFixDatasReponse()
潘栩锋's avatar
潘栩锋 committed
83
            {
84 85 86
                ADs = datas,
                thicks = thks,
                time = dt,
87
                ts = ts
88
            };
89

90
            UpdateTime = dt;
潘栩锋's avatar
潘栩锋 committed
91 92 93
        }

        #region IGageMode
94
        public void Start()
潘栩锋's avatar
潘栩锋 committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108
        {
            IsRunning = true;
        }

        public void Stop()
        {
            IsRunning = false;
        }

        #endregion


        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

109
        public void GetFixDatas(AsyncCBHandler asyncDelegate, object asyncContext)
潘栩锋's avatar
潘栩锋 committed
110
        {
111
            asyncDelegate(asyncContext, reponse);
潘栩锋's avatar
潘栩锋 committed
112 113 114
        }
    }
}