using System.Collections.Concurrent;
using WCS.Core;
using WCS.Entity;
using WCS.Entity.Protocol.Station;
namespace WCS.WorkEngineering.Extensions
{
///
/// 设备扩展
///
public static class DeviceExtension
{
public static bool IsConv(this Device source)
{
return source.HasProtocol(typeof(IStation521)) || source.HasProtocol(typeof(IStation520)) || source.HasProtocol(typeof(IStation522));
}
#region WCS_DEVICE扩展数据
private static ConcurrentDictionary DeviceValues = new ConcurrentDictionary();
public static void AddFlag(this Device source, DF flag)
{
var df = source.Get("DeviceFlag");
df = df | flag;
source.Set("DeviceFlag", df);
}
public static bool Is(this Device source, DF flag)
{
var df = source.Get("DeviceFlag");
return (df & flag) == flag;
}
public static void Set(this Device source, string key, T value)
{
DeviceValues[source.Code + key] = value;
}
public static T Get(this Device source, string key)
{
if (!DeviceValues.ContainsKey(source.Code + key))
return default(T);
return (T)DeviceValues[source.Code + key];
}
public static short Code(this Device source)
{
return short.Parse(source.Code);
}
public static string Tunnel(this Device source)
{
return source.Get("Tunnel");
}
public static int TunnelNum(this Device source)
{
return int.Parse(source.Tunnel().Last().ToString());
}
public static int Floor(this Device source)
{
return source.Get("Floor");
}
public static Device SC(this Device source)
{
return source.Get("SC");
}
public static Device RGV(this Device source)
{
return source.Get("RGV");
}
//public static LocInfo LocInfo(this WCS_DEVICEHdr source)
//{
// return source.Get("LocInfo");
//}
//public static bool WakeupOn(this WCS_DEVICEHdr source, int sec, string key)
//{
// var str = "WakeupOn" + key;
// var last = source.Get(str);
// if ((DateTime.Now - last).TotalMilliseconds > sec)
// {
// source.Set(str, DateTime.Now);
// return true;
// }
// else
// {
// Ltc.Log("OnSleep");
// return false;
// }
//}
//public static bool WakeupOn(this WCS_DEVICEHdr source, int sec)
//{
// return source.WakeupOn(sec, "");
//}
#endregion WCS_DEVICE扩展数据
//#region 静态方法
//public static WCS_DEVICEHdr[] Where(Func func)
//{
// var arr = LogicHandler.AllObjects.OfType().Where(func).ToArray();
// return arr;
//}
//public static WCS_DEVICEHdr Find(string code)
//{
// return Where(v => v.CODE == code).Single();
//}
//public static WCS_DEVICEHdr[] Find(params string[] codes)
//{
// return Where(v => codes.Contains(v.CODE)).ToArray();
//}
//public static void Set(string key, T value, params string[] devices)
//{
// var arr = LogicHandler.AllObjects.OfType().Where(v => devices.Contains(v.CODE)).ToArray();
// Parallel.ForEach(arr, v =>
// {
// v.Set(key, value);
// });
//}
//public static void Set(string key, T value, Func func)
//{
// var arr = LogicHandler.AllObjects.OfType().Where(func).ToArray();
// Parallel.ForEach(arr, v =>
// {
// v.Set(key, value);
// });
//}
//public static void AddFlag(DF flag, params string[] devices)
//{
// var arr = LogicHandler.AllObjects.OfType().Where(v => devices.Contains(v.CODE)).ToArray();
// Parallel.ForEach(arr, v =>
// {
// v.AddFlag(flag);
// });
//}
//public static void AddFlag(DF flag, Action callbck, params string[] devices)
//{
// var arr = LogicHandler.AllObjects.OfType().Where(v => devices.Contains(v.CODE)).ToArray();
// Parallel.ForEach(arr, v =>
// {
// v.AddFlag(flag);
// callbck?.Invoke(v);
// });
//}
//#endregion 静态方法
}
///
/// 设备配置
///
[Flags]
public enum DF
{
无 = 0,
SRM = 1 << 0,
SRM二级品取货 = 1 << 1,
SRM涂布取货 = 1 << 2,
SRM月台放货 = 1 << 3,
一楼RGV放货 = 1 << 4,
月台 = 1 << 5,
涂布RGV = 1 << 6,
BOPPRGV = 1 << 7,
涂布RGV取货设备组 = 1 << 8,
涂布RGV放货设备组 = 1 << 9,
涂布出库RGV取货站台 = 1 << 10,
涂布入库RGV取货站台 = 1 << 11,
SRM涂布放货 = 1 << 12,
涂布RGV取货站台 = 1 << 13,
BOPPRGV取货设备组 = 1 << 14,
BOPPRGV放货设备组 = 1 << 15,
SRMBOPP取货 = 1 << 16,
}
}