ClientNode.cs 5.5 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGVControl
{
    /// <summary>
    /// 客户端的节点
    /// </summary>
    public class ClientNode : Node
    {
        private string rfid = "00";

        /// <summary>
        /// RFID
        /// </summary>
        public string RFID
        {
            set
            {
                if (value.Length < 2)
                    rfid = value.PadLeft(2, '0');
                else
                    rfid = value;
            }
            get
            {
                return rfid;
            }
        }

        /// <summary>
        /// 小车名称
        /// </summary>
        public string AgvName { set; get; }

        /// <summary>
        /// 线体名(佳世达)
        /// </summary>
        public string LineName { set; get; }
        /// <summary>
        /// 节点位置的guid
        /// </summary>
        public string Pos_guid { set; get; }
        /// <summary>
        /// 节点位置名称
        /// </summary>
        public string Pos_name { get; set; }

        public ClientLevel ClientLevel { get; set; } = ClientLevel.Low;
        /// <summary>
        /// 节点位置坐标
        /// </summary>
        public PositionStru position;

        /// <summary>
        /// 空料架数量
        /// </summary>
        public int EmptyShelfCnt
        {
            get { return _EmptyShelfCnt; }

            set
            {
                EmptyShelfCnt = _EmptyShelfCnt;
            }
        }
        /// <summary>
        /// 空架子的RFID
        /// </summary>
        public List<string> EmptyShelfRFIDs;
        private int _EmptyShelfCnt = 0;
        public string AliceName { get; set; }
        /// <summary>
        /// 客户端节点
        /// </summary>
        /// <param name="name"></param>
        /// <param name="ip"></param>
        /// <param name="isUse"></param>
        public ClientNode(string name, string ip, string aliceName,string lineName, string pos_name, string pos_guid, bool isUse,int emptyCnt) : base(name, ip, isUse)
        {

            AliceName = aliceName;
            RFID = rfid;
            AgvName = "";
            Online = false;
            IsUse = isUse;
            _EmptyShelfCnt = emptyCnt;
            this.Pos_name = pos_name;
            this.Pos_guid = pos_guid;
            LineName = lineName;
            EmptyShelfRFIDs = new List<string>();
        }

        /// <summary>
        /// 客户端节点
        /// </summary>
        /// <param name="name"></param>
        /// <param name="rfid"></param>
        /// <param name="action"></param>
        /// <param name="level"></param>
        public ClientNode(string name, string rfid = "", eNodeStatus status = eNodeStatus.None) : base(name)
        {

            RFID = rfid;
            nodeStatus = status;
            AgvName = "";
        }
        /// <summary>
        ///空料架数量增加,如果RFID相同,不增加数量
        /// </summary>
        public void IncreEmptyShelfCnt(string rfid="")
        {
            if(!rfid.Equals("") && !EmptyShelfRFIDs.Contains(rfid))
            {
                System.Threading.Interlocked.Increment(ref _EmptyShelfCnt);
                EmptyShelfRFIDs.Add(rfid);
                Common.WriteIni(Name, SettingString.EmptyShelfCnt,_EmptyShelfCnt.ToString());
            }
            else if(rfid.Equals(""))
            {
                System.Threading.Interlocked.Increment(ref _EmptyShelfCnt);
                Common.WriteIni(Name, SettingString.EmptyShelfCnt, _EmptyShelfCnt.ToString());
            }
        }
        /// <summary>
        /// 空料架数量减少1
        /// </summary>
        public void DecreEmptyShelfCnt()
        {
            if (_EmptyShelfCnt > 0)
            {
                System.Threading.Interlocked.Decrement(ref _EmptyShelfCnt);
                Common.WriteIni(Name, SettingString.EmptyShelfCnt, _EmptyShelfCnt.ToString());
            }

            if(_EmptyShelfCnt.Equals(0) && EmptyShelfRFIDs.Count>0)
            {
                EmptyShelfRFIDs.Clear();
            }
        }
        /// <summary>
        /// 节点状态的文本形式
        /// </summary>
        /// <returns></returns>
        public string StatetText()
        {
            string s = string.Format("[Name={0}, NodeStatus={1}, RFID={2},ClientLevel ={3}]", Name, nodeStatus.ToString(), RFID, ClientLevel.ToString());
            return s;
        }

        public string[] ToRow()
        {
            //节点,IP,动作,RFID,AGV名称,在线,调用,清除AGV
            string[] s = new string[8];
            s[0] = AliceName;
            s[1] = IP;
            // if (Online)
            //  {
            s[2] = EmptyShelfCnt.ToString();//string.Format("({0},{1})", position.X.ToString("f2"), position.Y.ToString("f2"));
            s[3] = nodeStatus.ToString();
            s[4] = ClientLevel.ToString();
            s[5] = RFID;
          //  s[5] = AgvName;
            // }
            s[6] = Online ? "在线" : "离线";
            s[7] = IsUse ? "是" : "否";
           // s[8] = "清除";
            return s;
        }

        /// <summary>
        /// 脱机
        /// </summary>
        public void Offline()
        {
            RFID = "00";
            nodeStatus = eNodeStatus.None;
            AgvName = "";
            Online = false;
        }

        public virtual Job GetNewJob(Agv_Info agv)
        {
            return null;
        }
    }
}