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

using System.ComponentModel;
using System.Collections.ObjectModel;

using FObjBase;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;
潘栩锋's avatar
潘栩锋 committed
13
using Newtonsoft.Json;
潘栩锋's avatar
潘栩锋 committed
14 15 16

namespace FLY.Thick.Base.Client
{
17
    public class ScanCorrServiceClient : FObjServiceClient, IScanCorrService
潘栩锋's avatar
潘栩锋 committed
18 19
    {

20 21 22 23 24
        public ScanCorrServiceClient(UInt32 serviceId) : base(serviceId)
        {
            this.PropertyChanged += new PropertyChangedEventHandler(ScanCorrService_PropertyChanged);
        }
        public ScanCorrServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName)
潘栩锋's avatar
潘栩锋 committed
25 26 27 28 29 30 31 32
        {
            this.PropertyChanged += new PropertyChangedEventHandler(ScanCorrService_PropertyChanged);
        }

        void ScanCorrService_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Enable") 
            {
潘栩锋's avatar
潘栩锋 committed
33 34
                string json = JsonConvert.SerializeObject(Enable);

潘栩锋's avatar
潘栩锋 committed
35 36 37
                CurrObjSys.SetValueEx(
                   mConn, mServerID, ID, 
                   SCANCORR_OBJ_INTERFACE.SET_ENABLE,
潘栩锋's avatar
潘栩锋 committed
38
                   Misc.Converter.StringToBytes(json));
潘栩锋's avatar
潘栩锋 committed
39 40 41
            }
        }

42

潘栩锋's avatar
潘栩锋 committed
43 44 45
        #region IScanCorrService 成员

        
潘栩锋's avatar
潘栩锋 committed
46 47 48
        public bool Enable { get; set; }
        
        public int Progress { get; set; }
潘栩锋's avatar
潘栩锋 committed
49 50
        

潘栩锋's avatar
潘栩锋 committed
51
        public bool Ing { get; set; }
潘栩锋's avatar
潘栩锋 committed
52
        
潘栩锋's avatar
潘栩锋 committed
53
        public int ScanTimer { get; set; }
潘栩锋's avatar
潘栩锋 committed
54

潘栩锋's avatar
潘栩锋 committed
55 56
        public int SmoothFactor { get; set; }
        
潘栩锋's avatar
潘栩锋 committed
57 58 59
        /// <summary>
        /// 有效范围.开始,单位脉冲
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
60 61 62
        public int ValidBegin { get; set; }
        
        
潘栩锋's avatar
潘栩锋 committed
63 64 65
        /// <summary>
        /// 有效范围.结束,单位脉冲
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
66 67
        public int ValidEnd { get; set; } = 8000;
        
潘栩锋's avatar
潘栩锋 committed
68

潘栩锋's avatar
潘栩锋 committed
69 70 71 72 73
        
        public int PosOfGrid { get; set; } = 10;
        
        public int PosLen { get; set; } = 8000;
        
潘栩锋's avatar
潘栩锋 committed
74

潘栩锋's avatar
潘栩锋 committed
75 76 77
        public IScanCorrGroup Group0 { get; } = new ScanCorrGroup();
        
        public IScanCorrGroup Group1 { get; } = new ScanCorrGroup();
潘栩锋's avatar
潘栩锋 committed
78 79 80
        #endregion
        public void Smooth(int groupindex) 
        {
潘栩锋's avatar
潘栩锋 committed
81 82 83 84 85 86 87 88
            var p = new SCANCORR_OBJ_INTERFACE.Pack_CallStart()
            {
                groupindex = groupindex,
                smoothfactor = SmoothFactor
            };

            string json = JsonConvert.SerializeObject(p);

潘栩锋's avatar
潘栩锋 committed
89 90 91
            CurrObjSys.CallFunctionEx(
               mConn, mServerID, ID, 
               SCANCORR_OBJ_INTERFACE.CALL_SMOOTH,
潘栩锋's avatar
潘栩锋 committed
92
               Misc.Converter.StringToBytes(json));  
潘栩锋's avatar
潘栩锋 committed
93 94 95
        }
        public void Start(int groupindex) 
        {
潘栩锋's avatar
潘栩锋 committed
96 97 98 99 100 101 102
            var p = new SCANCORR_OBJ_INTERFACE.Pack_CallStart()
            {
                scantimer = ScanTimer,
                groupindex = groupindex,
                smoothfactor = SmoothFactor
            };
            string json = JsonConvert.SerializeObject(p);
潘栩锋's avatar
潘栩锋 committed
103 104 105 106

            CurrObjSys.CallFunctionEx(
                mConn, mServerID, ID, 
                SCANCORR_OBJ_INTERFACE.CALL_START,
潘栩锋's avatar
潘栩锋 committed
107
                Misc.Converter.StringToBytes(json));
潘栩锋's avatar
潘栩锋 committed
108 109 110
        }
        public void Clear(int groupindex) 
        {
潘栩锋's avatar
潘栩锋 committed
111 112 113 114 115 116
            var p = new SCANCORR_OBJ_INTERFACE.Pack_ClearRequest()
            {
                groupindex = groupindex
            };
            string json = JsonConvert.SerializeObject(p);

潘栩锋's avatar
潘栩锋 committed
117 118 119
            CurrObjSys.CallFunctionEx(
               mConn, mServerID, ID, 
               SCANCORR_OBJ_INTERFACE.CALL_CLEAR,
潘栩锋's avatar
潘栩锋 committed
120
               Misc.Converter.StringToBytes(json));
潘栩锋's avatar
潘栩锋 committed
121 122 123
        }
        public void Apply() 
        {
潘栩锋's avatar
潘栩锋 committed
124
            var p = new SCANCORR_OBJ_INTERFACE.Pack_ValidRange();
潘栩锋's avatar
潘栩锋 committed
125 126
            p.begin = ValidBegin;
            p.end = ValidEnd;
潘栩锋's avatar
潘栩锋 committed
127
            string json = JsonConvert.SerializeObject(p);
潘栩锋's avatar
潘栩锋 committed
128 129 130
            CurrObjSys.SetValueEx(
                mConn, mServerID, ID, 
                SCANCORR_OBJ_INTERFACE.SET_VALIDRANGE,
潘栩锋's avatar
潘栩锋 committed
131
                Misc.Converter.StringToBytes(json));
潘栩锋's avatar
潘栩锋 committed
132
        }
133

潘栩锋's avatar
潘栩锋 committed
134 135
        public override void ConnectNotify(IFConn from)
        {
136
            base.ConnectNotify(from);
潘栩锋's avatar
潘栩锋 committed
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
            if (from.IsConnected) 
            {
                CurrObjSys.SenseConfigEx(
                    mConn, mServerID, ID, 0xffffffff, SENSE_CONFIG.ADD);

                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID, 
                    SCANCORR_OBJ_INTERFACE.GET_PROGRESS);


                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID, 
                    SCANCORR_OBJ_INTERFACE.GET_ENABLE);


                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID, 
                    SCANCORR_OBJ_INTERFACE.GET_START_PARAMS);


                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID, 
                    SCANCORR_OBJ_INTERFACE.GET_GROUP_PARAMS);


                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID, 
                    SCANCORR_OBJ_INTERFACE. GET_GROUP0_FORW);


                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID, 
                    SCANCORR_OBJ_INTERFACE.GET_GROUP0_BACKW);


                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID, 
                    SCANCORR_OBJ_INTERFACE.GET_GROUP1_FORW);


                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID, 
                    SCANCORR_OBJ_INTERFACE.GET_GROUP1_BACKW);

                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID,
                    SCANCORR_OBJ_INTERFACE.GET_VALIDRANGE);
            }
        }
        public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            PushInfo(from, srcid, memid, infodata);
        }
        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {
            switch (infoid) 
            {
                case SCANCORR_OBJ_INTERFACE.PUSH_PROGRESS: 
                    {
潘栩锋's avatar
潘栩锋 committed
196 197
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<SCANCORR_OBJ_INTERFACE.Pack_GetState>(json);
潘栩锋's avatar
潘栩锋 committed
198 199 200 201 202
                        Progress = p.progress;
                        Ing = p.ing;
                    }break;
                case SCANCORR_OBJ_INTERFACE.PUSH_ENABLE:
                    {
潘栩锋's avatar
潘栩锋 committed
203 204 205
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<bool>(json);
                        Enable = p;
潘栩锋's avatar
潘栩锋 committed
206 207 208 209

                    }break;
                case SCANCORR_OBJ_INTERFACE.PUSH_START_PARAMS:
                    {
潘栩锋's avatar
潘栩锋 committed
210 211
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<SCANCORR_OBJ_INTERFACE.Pack_StartParams>(json);
潘栩锋's avatar
潘栩锋 committed
212 213 214 215 216 217 218
                        SmoothFactor = p.smoothfactor;
                        ScanTimer = p.scantimer;
                        PosOfGrid = p.posofgrid;
                        PosLen = p.poslen;
                    }break;
                case SCANCORR_OBJ_INTERFACE.GET_GROUP_PARAMS:
                    {
潘栩锋's avatar
潘栩锋 committed
219 220
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<SCANCORR_OBJ_INTERFACE.Pack_GroupParams>(json);
潘栩锋's avatar
潘栩锋 committed
221 222 223 224 225 226
                        Group0.AvgAD = p.avgad0;
                        Group1.AvgAD = p.avgad1;

                    }break;
                case SCANCORR_OBJ_INTERFACE.PUSH_GROUP0_FORW:
                    {
潘栩锋's avatar
潘栩锋 committed
227 228 229
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<List<int>>(json);
                        ((ScanCorrGroup)Group0).UpdateForwDatas(p);
潘栩锋's avatar
潘栩锋 committed
230 231 232
                    }break;
                case SCANCORR_OBJ_INTERFACE.PUSH_GROUP0_BACKW:
                    {
潘栩锋's avatar
潘栩锋 committed
233 234 235
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<List<int>>(json);
                        ((ScanCorrGroup)Group0).UpdateBackwDatas(p);
潘栩锋's avatar
潘栩锋 committed
236 237 238
                    } break;
                case SCANCORR_OBJ_INTERFACE.PUSH_GROUP1_FORW:
                    {
潘栩锋's avatar
潘栩锋 committed
239 240 241
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<List<int>>(json);
                        ((ScanCorrGroup)Group1).UpdateForwDatas(p);
潘栩锋's avatar
潘栩锋 committed
242 243 244
                    } break;
                case SCANCORR_OBJ_INTERFACE.PUSH_GROUP1_BACKW:
                    {
潘栩锋's avatar
潘栩锋 committed
245 246 247
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<List<int>>(json);
                        ((ScanCorrGroup)Group1).UpdateBackwDatas(p);
潘栩锋's avatar
潘栩锋 committed
248 249 250
                    } break;
                case SCANCORR_OBJ_INTERFACE.PUSH_VALIDRANGE:
                    {
潘栩锋's avatar
潘栩锋 committed
251 252 253 254
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<SCANCORR_OBJ_INTERFACE.Pack_ValidRange>(json);
                        ValidBegin = p.begin;
                        ValidEnd = p.end;
潘栩锋's avatar
潘栩锋 committed
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
                    }break;
            }
        }
    }
    public class ScanCorrGroup :IScanCorrGroup
    {
        private int _avgad = -1;
        /// <summary>
        /// 平均AD值
        /// </summary>
        public int AvgAD
        {
            get { return _avgad; }
            set
            {
                _avgad = value;
                NotifyPropertyChanged("AvgAD");
            }
        }

        private List<int> forwdatas = new List<int>();
        /// <summary>
        /// 正方向机架AD值数据, grid数据
        /// </summary>
        public List<int> ForwDatas
        {
            get { return forwdatas; }
        }
        public void UpdateForwDatas(List<int> data)
        {
            ForwDatas.Clear();
            ForwDatas.AddRange(data);

            NotifyPropertyChanged("ForwDatas");
        }
        public void UpdateBackwDatas(List<int> data) 
        {
            BackwDatas.Clear();
            BackwDatas.AddRange(data);
            NotifyPropertyChanged("BackwDatas");
        }
        private List<int> backwdatas = new List<int>();

        /// <summary>
        /// 反方向机架AD值数据, grid数据
        /// </summary>
        public List<int> BackwDatas { get { return backwdatas; } }
        public ScanCorrGroup() 
        {

        }
        #region INotifyPropertyChanged 成员
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion


    }
    
}