ClientNode.cs 4.0 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 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
            {
                if(Common.missionManager !=null && Common.missionManager.GetUnlockInfo(Name) !=null)
                {
                    return Common.missionManager.GetUnlockCnt(Name);
                }
                return 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;
            Online = false;
            IsUse = isUse;
            this.Pos_name = pos_name;
            this.Pos_guid = pos_guid;
            LineName = lineName;
        }

        /// <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;
        }

        /// <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;
            Online = false;
        }

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