Blowing_OBJProxy.cs 5.12 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4

using FLY.Thick.Blowing.IService;
using FLY.Thick.Blowing.OBJ_INTERFACE;
using FObjBase;
潘栩锋's avatar
潘栩锋 committed
5
using Newtonsoft.Json;
潘栩锋's avatar
潘栩锋 committed
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FLY.Thick.Blowing.Server.OBJProxy
{
    /// <summary>
    /// 吹膜测厚 OBJ 服务代理
    /// </summary>
    public class Blowing_OBJProxy: FObj
    {
        #region 延时推送 MARKNO
        const int MARKNO_PUSH_PARAMS = 1;
        const int MARKNO_PUSH_MAP = 2;
        #endregion
        
        IBlowing mRenZiJia;
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="objsys_idx"></param>
        /// <param name="renzijia"></param>
        public Blowing_OBJProxy(int objsys_idx, IBlowing renzijia) : base(objsys_idx)
        {
            ID = OBJ_INTERFACE_ID.RENZIJIA_ID;
            mRenZiJia = renzijia;
            mRenZiJia.PropertyChanged += mRenZiJiaFix_PropertyChanged;
            mRenZiJia.DataEvent += mRenZiJia_DataEvent;
        }

        void mRenZiJia_DataEvent(object sender, RenZiJiaDataEventArgs e)
        {
潘栩锋's avatar
潘栩锋 committed
40
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(e);
潘栩锋's avatar
潘栩锋 committed
41 42
            CurrObjSys.PushObjInfoEx(
                this, BLOWINGFIX_OBJ_INTERFACE.PUSH_DATA,
潘栩锋's avatar
潘栩锋 committed
43
                Misc.Converter.StringToBytes(json));
潘栩锋's avatar
潘栩锋 committed
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
        }

        void mRenZiJiaFix_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (
                (e.PropertyName == "ChannelCnt") ||
                (e.PropertyName == "BPC") ||
                (e.PropertyName == "OrgBoltNo")
                )
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate ()
                    {
                        byte[] buf;
                        GetValue(null, 0, BLOWING_OBJ_INTERFACE.GET_PARAMS, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, BLOWING_OBJ_INTERFACE.PUSH_PARAMS,
                            buf);
                    }), this, MARKNO_PUSH_PARAMS);
            }
            if (
                (e.PropertyName == "Map") ||
                (e.PropertyName == "IsUsedMap"))
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate ()
                    {
                        byte[] buf;
                        GetValue(null, 0, BLOWING_OBJ_INTERFACE.GET_MAP, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, BLOWING_OBJ_INTERFACE.GET_MAP,
                            buf);
                    }), this, MARKNO_PUSH_MAP);
            }
        }

        public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
        {
            switch (memid)
            {
                case BLOWING_OBJ_INTERFACE.GET_PARAMS:
                    {
                        BLOWING_OBJ_INTERFACE.Pack_Params p = new BLOWING_OBJ_INTERFACE.Pack_Params()
                        {

                            channelcnt = mRenZiJia.ChannelCnt,
                            bpc = mRenZiJia.BPC,
                            orgBolt = mRenZiJia.OrgBoltNo
                        };
潘栩锋's avatar
潘栩锋 committed
93 94
                        string json = JsonConvert.SerializeObject(p);
                        infodata = Misc.Converter.StringToBytes(json);
潘栩锋's avatar
潘栩锋 committed
95 96 97 98
                    }
                    break;
                case BLOWING_OBJ_INTERFACE.GET_MAP:
                    {
潘栩锋's avatar
潘栩锋 committed
99
                        string json = JsonConvert.SerializeObject(new BLOWING_OBJ_INTERFACE.Pack_Map()
潘栩锋's avatar
潘栩锋 committed
100 101 102
                        {
                            IsUsedMap = mRenZiJia.IsUsedMap,
                            Map = mRenZiJia.Map
潘栩锋's avatar
潘栩锋 committed
103 104
                        });
                        infodata = Misc.Converter.StringToBytes(json);
潘栩锋's avatar
潘栩锋 committed
105 106 107 108 109 110 111 112 113 114 115 116 117
                    }
                    break;
                default:
                    infodata = null;
                    break;
            }
        }
        public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case BLOWING_OBJ_INTERFACE.SET_PARAMS:
                    {
潘栩锋's avatar
潘栩锋 committed
118 119
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<BLOWING_OBJ_INTERFACE.Pack_Params>(json);
潘栩锋's avatar
潘栩锋 committed
120 121 122 123 124 125 126 127 128
                        mRenZiJia.ChannelCnt = p.channelcnt;
                        mRenZiJia.BPC = p.bpc;
                        mRenZiJia.OrgBoltNo = p.orgBolt;
                        mRenZiJia.Apply();
                        
                    }
                    break;
                case BLOWING_OBJ_INTERFACE.SET_MAP:
                    {
潘栩锋's avatar
潘栩锋 committed
129 130
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<BLOWING_OBJ_INTERFACE.Pack_Map>(json);
潘栩锋's avatar
潘栩锋 committed
131 132 133 134 135 136 137 138 139
                        mRenZiJia.IsUsedMap = p.IsUsedMap;
                        mRenZiJia.Map = p.Map.ToList();
                        mRenZiJia.Apply();
                    }
                    break;
            }
        }
    }
}