ScanCorr_OBJProxy.cs 13.6 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 FObjBase;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.Server;
潘栩锋's avatar
潘栩锋 committed
10
using Newtonsoft.Json;
潘栩锋's avatar
潘栩锋 committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

namespace FLY.Thick.Base.Server.OBJProxy
{
    public class ScanCorr_OBJProxy : FObj
    {
        #region 延时推送 MARKNO
        const int MARKNO_PUSH_GROUP_PARAMS = 1;
        const int MARKNO_PUSH_GROUP0_FORW = 2;
        const int MARKNO_PUSH_GROUP0_BACKW = 3;
        const int MARKNO_PUSH_GROUP1_FORW = 4;
        const int MARKNO_PUSH_GROUP1_BACKW = 5;
        const int MARKNO_PUSH_PROGRESS = 6;
        const int MARKNO_PUSH_START_PARAMS = 7;
        const int MARKNO_PUSH_ENABLE = 8;
        const int MARKNO_PUSH_VALIDRANGE = 9;
        #endregion

28
        IScanCorrService mScanCorr;
潘栩锋's avatar
潘栩锋 committed
29

30
        public ScanCorr_OBJProxy(int objsys_idx, UInt32 id, IScanCorrService scancorr)
潘栩锋's avatar
潘栩锋 committed
31 32
            : base(objsys_idx)
        {
潘栩锋's avatar
潘栩锋 committed
33
            ID = id;
潘栩锋's avatar
潘栩锋 committed
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
            mScanCorr = scancorr;

            mScanCorr.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mScanCorr_PropertyChanged);
            mScanCorr.Group0.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Group0_PropertyChanged);
            mScanCorr.Group1.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Group1_PropertyChanged);
            
        }

        void Group0_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if ((e.PropertyName == "AvgAD") || (e.PropertyName == "DataReady"))
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, SCANCORR_OBJ_INTERFACE.GET_GROUP_PARAMS, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, SCANCORR_OBJ_INTERFACE.PUSH_GROUP_PARAMS,
                            buf);
                    }), this, MARKNO_PUSH_GROUP_PARAMS);
            }
            else if (e.PropertyName == "ForwDatas") 
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, SCANCORR_OBJ_INTERFACE.GET_GROUP0_FORW, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, SCANCORR_OBJ_INTERFACE.PUSH_GROUP0_FORW,
                            buf);
                    }), this, MARKNO_PUSH_GROUP0_FORW);
            }
            else if (e.PropertyName == "BackwDatas") 
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, SCANCORR_OBJ_INTERFACE.GET_GROUP0_BACKW, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, SCANCORR_OBJ_INTERFACE.PUSH_GROUP0_BACKW,
                            buf);
                    }), this, MARKNO_PUSH_GROUP0_BACKW);
            }
        }
        void Group1_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if ((e.PropertyName == "AvgAD") || (e.PropertyName == "DataReady"))
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, SCANCORR_OBJ_INTERFACE.GET_GROUP_PARAMS, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, SCANCORR_OBJ_INTERFACE.PUSH_GROUP_PARAMS,
                            buf);
                    }), this, MARKNO_PUSH_GROUP_PARAMS);
            }
            else if (e.PropertyName == "ForwDatas")
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, SCANCORR_OBJ_INTERFACE.GET_GROUP1_FORW, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, SCANCORR_OBJ_INTERFACE.PUSH_GROUP1_FORW,
                            buf);
                    }), this, MARKNO_PUSH_GROUP1_FORW);
            }
            else if (e.PropertyName == "BackwDatas")
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, SCANCORR_OBJ_INTERFACE.GET_GROUP1_BACKW, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, SCANCORR_OBJ_INTERFACE.PUSH_GROUP1_BACKW,
                            buf);
                    }), this, MARKNO_PUSH_GROUP1_BACKW);
            }
        }

        void mScanCorr_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if ((e.PropertyName == "Progress") || (e.PropertyName == "Ing"))
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, SCANCORR_OBJ_INTERFACE.GET_PROGRESS, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, SCANCORR_OBJ_INTERFACE.PUSH_PROGRESS,
                            buf);
                    }), this, MARKNO_PUSH_PROGRESS);
            }
            else if ((e.PropertyName == "ScanTimer") || (e.PropertyName == "SmoothFactor")|| (e.PropertyName == "PosLen")||(e.PropertyName == "PosOfGrid")) 
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, SCANCORR_OBJ_INTERFACE.GET_START_PARAMS, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, SCANCORR_OBJ_INTERFACE.PUSH_START_PARAMS,
                            buf);
                    }), this, MARKNO_PUSH_START_PARAMS);
            }
            else if (e.PropertyName == "Enable") 
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, SCANCORR_OBJ_INTERFACE.GET_ENABLE, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, SCANCORR_OBJ_INTERFACE.PUSH_ENABLE,
                            buf);
                    }), this, MARKNO_PUSH_ENABLE);
            }
            else if ((e.PropertyName == "ValidBegin")||
                (e.PropertyName == "ValidEnd"))
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, SCANCORR_OBJ_INTERFACE.GET_VALIDRANGE, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, SCANCORR_OBJ_INTERFACE.PUSH_VALIDRANGE,
                            buf);
                    }), this, MARKNO_PUSH_VALIDRANGE);
            }
        }


        public override void CallFunction(IFConn from, uint srcid,UInt32 magic, ushort funcid, byte[] infodata)
        {
            switch (funcid)
            {
                case SCANCORR_OBJ_INTERFACE.CALL_START:
                    {
潘栩锋's avatar
潘栩锋 committed
181 182 183 184 185
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<SCANCORR_OBJ_INTERFACE.Pack_CallStart>(json);
                        mScanCorr.SmoothFactor = p.smoothfactor;
                        mScanCorr.ScanTimer = p.scantimer;
                        mScanCorr.Start(p.groupindex);
潘栩锋's avatar
潘栩锋 committed
186 187 188
                    } break;
                case SCANCORR_OBJ_INTERFACE.CALL_CLEAR:
                    {
潘栩锋's avatar
潘栩锋 committed
189 190 191
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<SCANCORR_OBJ_INTERFACE.Pack_ClearRequest>(json);
                        mScanCorr.Clear(p.groupindex);
潘栩锋's avatar
潘栩锋 committed
192 193 194
                    } break;
                case SCANCORR_OBJ_INTERFACE.CALL_SMOOTH:
                    {
潘栩锋's avatar
潘栩锋 committed
195 196 197 198
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<SCANCORR_OBJ_INTERFACE.Pack_CallStart>(json);
                        mScanCorr.SmoothFactor = p.smoothfactor;
                        mScanCorr.Smooth(p.groupindex);
潘栩锋's avatar
潘栩锋 committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
                    } break;
                default:
                    infodata = null;
                    break;
            }
        }
        public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
        {
            switch (memid)
            {
                case SCANCORR_OBJ_INTERFACE.GET_PROGRESS:
                    {
                        SCANCORR_OBJ_INTERFACE.Pack_GetState p = new SCANCORR_OBJ_INTERFACE.Pack_GetState();
                        p.progress = mScanCorr.Progress;
                        p.ing = mScanCorr.Ing;
潘栩锋's avatar
潘栩锋 committed
214 215 216
                        string json = JsonConvert.SerializeObject(p);

                        infodata = Misc.Converter.StringToBytes(json);
潘栩锋's avatar
潘栩锋 committed
217 218 219
                    } break;
                case SCANCORR_OBJ_INTERFACE.GET_ENABLE:
                    {
潘栩锋's avatar
潘栩锋 committed
220 221
                        string json = JsonConvert.SerializeObject(mScanCorr.Enable);
                        infodata = Misc.Converter.StringToBytes(json);
潘栩锋's avatar
潘栩锋 committed
222 223 224 225 226 227 228 229
                    } break;
                case SCANCORR_OBJ_INTERFACE.GET_START_PARAMS:
                    {
                        SCANCORR_OBJ_INTERFACE.Pack_StartParams p = new SCANCORR_OBJ_INTERFACE.Pack_StartParams();
                        p.scantimer = mScanCorr.ScanTimer;
                        p.smoothfactor = mScanCorr.SmoothFactor;
                        p.posofgrid = mScanCorr.PosOfGrid;
                        p.poslen = mScanCorr.PosLen;
潘栩锋's avatar
潘栩锋 committed
230 231
                        string json = JsonConvert.SerializeObject(p);
                        infodata = Misc.Converter.StringToBytes(json);
潘栩锋's avatar
潘栩锋 committed
232 233 234 235 236 237
                    } break;
                case SCANCORR_OBJ_INTERFACE.GET_GROUP_PARAMS:
                    {
                        SCANCORR_OBJ_INTERFACE.Pack_GroupParams p = new SCANCORR_OBJ_INTERFACE.Pack_GroupParams();
                        p.avgad0 = mScanCorr.Group0.AvgAD;
                        p.avgad1 = mScanCorr.Group1.AvgAD;
潘栩锋's avatar
潘栩锋 committed
238 239 240 241
                        string json = JsonConvert.SerializeObject(p);
                        infodata = Misc.Converter.StringToBytes(json);
                    }
                    break;
潘栩锋's avatar
潘栩锋 committed
242 243
                case SCANCORR_OBJ_INTERFACE.GET_GROUP0_FORW:
                    {
潘栩锋's avatar
潘栩锋 committed
244 245 246 247
                        string json = JsonConvert.SerializeObject(mScanCorr.Group0.ForwDatas);
                        infodata = Misc.Converter.StringToBytes(json);
                    }
                    break;
潘栩锋's avatar
潘栩锋 committed
248 249
                case SCANCORR_OBJ_INTERFACE.GET_GROUP0_BACKW:
                    {
潘栩锋's avatar
潘栩锋 committed
250 251
                        string json = JsonConvert.SerializeObject(mScanCorr.Group0.BackwDatas);
                        infodata = Misc.Converter.StringToBytes(json);
潘栩锋's avatar
潘栩锋 committed
252 253 254
                    } break;
                case SCANCORR_OBJ_INTERFACE.GET_GROUP1_FORW:
                    {
潘栩锋's avatar
潘栩锋 committed
255 256
                        string json = JsonConvert.SerializeObject(mScanCorr.Group1.ForwDatas);
                        infodata = Misc.Converter.StringToBytes(json);
潘栩锋's avatar
潘栩锋 committed
257 258 259
                    } break;
                case SCANCORR_OBJ_INTERFACE.GET_GROUP1_BACKW:
                    {
潘栩锋's avatar
潘栩锋 committed
260 261
                        string json = JsonConvert.SerializeObject(mScanCorr.Group1.BackwDatas);
                        infodata = Misc.Converter.StringToBytes(json);
潘栩锋's avatar
潘栩锋 committed
262 263 264 265 266 267
                    } break;
                case SCANCORR_OBJ_INTERFACE.GET_VALIDRANGE:
                    {
                        SCANCORR_OBJ_INTERFACE.Pack_ValidRange p = new SCANCORR_OBJ_INTERFACE.Pack_ValidRange();
                        p.begin = mScanCorr.ValidBegin;
                        p.end = mScanCorr.ValidEnd;
潘栩锋's avatar
潘栩锋 committed
268 269 270 271
                        string json = JsonConvert.SerializeObject(p);
                        infodata = Misc.Converter.StringToBytes(json);
                    }
                    break;
潘栩锋's avatar
潘栩锋 committed
272 273 274 275 276 277 278 279 280 281 282
                default:
                    infodata = null;
                    break;
            }
        }
        public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case SCANCORR_OBJ_INTERFACE.SET_ENABLE:
                    {
潘栩锋's avatar
潘栩锋 committed
283 284 285
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<bool>(json);
                        mScanCorr.Enable = p;
潘栩锋's avatar
潘栩锋 committed
286 287 288 289
                        mScanCorr.Apply();
                    } break;
                case SCANCORR_OBJ_INTERFACE.SET_VALIDRANGE:
                    {
潘栩锋's avatar
潘栩锋 committed
290 291
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<SCANCORR_OBJ_INTERFACE.Pack_ValidRange>(json);
潘栩锋's avatar
潘栩锋 committed
292 293 294 295 296 297 298 299 300
                        mScanCorr.ValidBegin = p.begin;
                        mScanCorr.ValidEnd = p.end;
                        mScanCorr.Apply();
                    } break;
            }
        }

    }
}