BlowingScan_OBJProxy.cs 5.72 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;
using FLY.Thick.BlowingScan.OBJ_INTERFACE;
using FLY.Thick.BlowingScan.Server;
using FLY.Thick.BlowingScan.IService;
using FLY.Thick.BlowingScan.Common;
using FLY.Thick.Blowing.Server.OBJProxy;
using Newtonsoft.Json;

namespace FLY.Thick.BlowingScan.Server.OBJProxy
{
    public class BlowingScan_OBJProxy : Blowing_OBJProxy
    {
        #region 延时推送 MARKNO
        const int MARKNO_PUSH_PARAMSEXT = 2;
        const int MARKNO_PUSH_STATUS = 3;
        const int MARKNO_PUSH_BUFINFO = 4;
        #endregion


        IBlowingScanService mBlowing;



28
        public BlowingScan_OBJProxy(int objsys_idx,UInt32 id, IBlowingScanService blowing) :base(objsys_idx,id, blowing)
潘栩锋's avatar
潘栩锋 committed
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
        {
            mBlowing = blowing;
            mBlowing.PropertyChanged += mBlowing_PropertyChanged;
        }

        void mBlowing_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (
                (e.PropertyName == "SolveCnt") ||
                (e.PropertyName == "SensorWidth")||
                (e.PropertyName == "Smooth")
                )
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate ()
                    {
                        byte[] buf;
                        GetValue(null, 0, BLOWING_SCAN_OBJ_INTERFACE.GET_PARAMSEXT, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, BLOWING_SCAN_OBJ_INTERFACE.PUSH_PARAMSEXT,
                            buf);
                    }), this, MARKNO_PUSH_PARAMSEXT);
            }
            else if (
                (e.PropertyName == "FirstBM") ||
                (e.PropertyName == "LastBM")
                )
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate ()
                    {
                        byte[] buf;
                        GetValue(null, 0, BLOWING_SCAN_OBJ_INTERFACE.GET_BUFINFO, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, BLOWING_SCAN_OBJ_INTERFACE.PUSH_BUFINFO,
                            buf);
                    }), this, MARKNO_PUSH_BUFINFO);
            }
        }
        
        public override void CallFunction(IFConn from, uint srcid,UInt32 magic, ushort funcid, byte[] infodata)
        {
            switch (funcid) 
            {
                case BLOWING_SCAN_OBJ_INTERFACE.CALL_GETBUF:
                    {
                        mBlowing.GetBufList(
                            new AsyncCBHandler(delegate (object AsyncState, object retdata)
                            {
                                ConnContext context = (ConnContext)AsyncState;
                                GetBufListReponse p = (GetBufListReponse)retdata;
                                string json = JsonConvert.SerializeObject(p);
                                CurrObjSys.PushCallFunctionEx(
                                    context.from,
                                    context.srcid,
                                    ID,
                                    context.magic,
                                    BLOWING_SCAN_OBJ_INTERFACE.CALL_GETBUF,
                                    Misc.Converter.StringToBytes(json));
                            }), new ConnContext(from, srcid, magic));
                    } break;
            }
        }

        public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
        {
            base.GetValue(from, srcid, memid, out infodata);
            if (infodata != null)
                return;

            switch (memid) 
            {
                case BLOWING_SCAN_OBJ_INTERFACE.GET_PARAMSEXT:
                    {
                        BLOWING_SCAN_OBJ_INTERFACE.Pack_ParamsExt p = new BLOWING_SCAN_OBJ_INTERFACE.Pack_ParamsExt(){
                            solveCnt = mBlowing.SolveCnt,
                            sensorWidth = mBlowing.SensorWidth,
                            smooth = mBlowing.Smooth
                        };
                        string json = JsonConvert.SerializeObject(p);
                        infodata = Misc.Converter.StringToBytes(json);
                    }break;
                    
                case BLOWING_SCAN_OBJ_INTERFACE.GET_BUFINFO:
                    {
                        BLOWING_SCAN_OBJ_INTERFACE.Pack_BM p = new BLOWING_SCAN_OBJ_INTERFACE.Pack_BM()
                        {
                            firstbm = mBlowing.FirstBM,
                            lastbm = mBlowing.LastBM
                        };
                        string json = JsonConvert.SerializeObject(p);
                        infodata = Misc.Converter.StringToBytes(json);
                    }
                    break;
                default:
                    infodata = null;
                    break;
            }
        }
        public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            base.SetValue(from, srcid, memid, infodata);
            switch (memid)
            {
                case BLOWING_SCAN_OBJ_INTERFACE.SET_PARAMSEXT:
                    {

                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<BLOWING_SCAN_OBJ_INTERFACE.Pack_ParamsExt>(json);

                        mBlowing.SolveCnt = p.solveCnt;
                        mBlowing.SensorWidth = p.sensorWidth;
                        mBlowing.Smooth = p.smooth;
                        mBlowing.Apply();
                        
                    } break;
            }         
        }
    }

}