BlowingServiceClient.cs 4.84 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
using FLY.Thick.Blowing.IService;
using FLY.Thick.Blowing.OBJ_INTERFACE;
using FObjBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace FLY.Thick.Blowing.Client
{
    public class BlowingServiceClient : FObj, IBlowing
    {
        protected IFConn mConn;
        protected UInt32 mServerID;
16 17
        
        public bool IsConnected { get; set; }
潘栩锋's avatar
潘栩锋 committed
18 19 20 21 22 23

        #region IBlowing 成员变量
        #region 分区设定
        /// <summary>
        /// 加热通道数
        /// </summary>
24 25
        public int ChannelCnt { get; set; } = 44;

潘栩锋's avatar
潘栩锋 committed
26 27 28 29

        /// <summary>
        /// 分区数/加热通道数
        /// </summary>
30
        public int BPC { get; set; } = 2;
潘栩锋's avatar
潘栩锋 committed
31 32 33 34 35 36 37 38 39 40 41


        /// <summary>
        /// 风环螺丝数
        /// </summary>
        public int NBolts
        {
            get { return ChannelCnt * BPC; }
        }


42 43
        
        public int OrgBoltNo { get; set; } = 1;
潘栩锋's avatar
潘栩锋 committed
44 45 46 47

        /// <summary>
        /// 使用分区表
        /// </summary>
48 49
        public bool IsUsedMap { get; set; }

潘栩锋's avatar
潘栩锋 committed
50 51 52 53

        /// <summary>
        /// 分区表
        /// </summary>
54 55
        public List<BoltMapCell> Map { get; set; } = new List<BoltMapCell>();

潘栩锋's avatar
潘栩锋 committed
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
        #endregion


        #endregion

        /// <summary>
        /// 每次有新数据时候推送。 修改参数,不会推送
        /// </summary>
        public event RenZiJiaDataEventHandler DataEvent;

        public BlowingServiceClient()
        {
            mServerID = FLY.Thick.Blowing.OBJ_INTERFACE.OBJ_INTERFACE_ID.RENZIJIA_ID;
        }

        #region 功能
        public virtual void Apply()
        {
            CurrObjSys.SetValueEx(
                mConn, mServerID, ID,
                BLOWING_OBJ_INTERFACE.SET_PARAMS,
                new BLOWING_OBJ_INTERFACE.Pack_Params()
                {
                    channelcnt = ChannelCnt,
                    bpc = BPC,
                    orgBolt = OrgBoltNo
                }.ToBytes());

            CurrObjSys.SetValueEx(
                mConn, mServerID, ID,
                BLOWING_OBJ_INTERFACE.SET_MAP,
                new BLOWING_OBJ_INTERFACE.Pack_Map()
                {
                    IsUsedMap = IsUsedMap,
                    Map = Map
                }.ToBytes());
        }

        #endregion


        #region INotifyPropertyChanged 成员
98

潘栩锋's avatar
潘栩锋 committed
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
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        public override void Dispose()
        {
            CurrObjSys.ObjRemove(
                this, mConn);
        }
        public override void ConnectNotify(IFConn from)
        {
            mConn = from;
            IsConnected = from.IsConnected;
            if (from.IsConnected)
            {
                //获取所有数据,设置推送
                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID,
                    BLOWING_OBJ_INTERFACE.GET_PARAMS);

                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID,
                    BLOWING_OBJ_INTERFACE.GET_MAP);

                CurrObjSys.SenseConfigEx(
                    mConn, mServerID, ID, 0xffffffff,
                    SENSE_CONFIG.ADD);

            }
        }
        public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case BLOWING_OBJ_INTERFACE.GET_PARAMS:
                    {
                        BLOWING_OBJ_INTERFACE.Pack_Params p = new BLOWING_OBJ_INTERFACE.Pack_Params();
                        if (!p.TryParse(infodata))
                            break;

                        ChannelCnt = p.channelcnt;//总分区数,从1开始
                        BPC = p.bpc;
                        OrgBoltNo = p.orgBolt;
                    }
                    break;
                case BLOWING_OBJ_INTERFACE.GET_MAP:
                    {
                        BLOWING_OBJ_INTERFACE.Pack_Map p = new BLOWING_OBJ_INTERFACE.Pack_Map();
                        if (!p.TryParse(infodata))
                            break;
                        IsUsedMap = p.IsUsedMap;
                        Map = p.Map;
                    }
                    break;
            }
        }
        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {
            switch (infoid)
            {
                case BLOWING_OBJ_INTERFACE.PUSH_DATA:
                    {
                        RenZiJiaDataEventArgs e = new RenZiJiaDataEventArgs();
                        if (!e.TryParse(infodata))
                            return;
                        DataEvent?.Invoke(this, e);
                    }
                    break;
                default:
                    PushGetValue(from, srcid, infoid, infodata);
                    break;
            }
        }

       
    }
}