using Aitex.Core.RT.Log;
using Aitex.Core.Util;
using CyberX8_Core;
using CyberX8_RT.Devices.EFEM;
using MECF.Framework.Common.Equipment;
using MECF.Framework.Common.SubstrateTrackings;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CyberX8_RT.Modules.EFEM
{
    public class EfemAutoMessageProcessor
    {
        #region 内部变量
        /// 
        /// EFEM对象
        ///  
        private EfemBase _efem;
        /// 
        /// 指令 
        ///  
        private ConcurrentQueue _commands = new ConcurrentQueue();
        #endregion
        /// 
        /// 构造函数
        ///  
        /// 
        /// 发送指令
        ///  
        /// 
        /// 是否存在队列
        ///  
        ///  queues = _commands.ToList();
            foreach (var item in queues)
            {
                EfemEntity.MSG itemMsg = (EfemEntity.MSG)item[0];
                ModuleName itemModule = (ModuleName)item[1];
                if (itemMsg == msg&&itemModule==moduleName)
                {
                    return true;
                }
            }
            return false;
        }
        /// 
        /// 监控
        ///  
        public void Monitor()
        {
            if (Singleton.Instance.EFEM.RobotStatus != RState.Running)
            {
                if (Singleton.Instance.EFEM.RobotStatus==RState.End)
                {
                    if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
                    {
                        return;
                    }
                    if (_commands.Count > 0 && _commands.TryDequeue(out object[] args))
                    {
                        EfemEntity.MSG cmd = (EfemEntity.MSG)args[0];
                        LOG.WriteLog(eEvent.EV_EFEM_ROBOT, ModuleName.EfemRobot.ToString(), $"execute {cmd}");
                        ProcessBackroundCommand(cmd, args);
                    }
                }
            }
        }
        /// 
        /// 处理指令
        ///  
        ///