LimitAreaInfo.cs
4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
98
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
using log4net.Util;
using Mushiny;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
namespace CtuDeviceLib
{
public class LimitAreaInfo
{
/// <summary>
/// 限制区域名
/// </summary>
public string Name { get; set; } = "";
/// <summary>
/// 占用的AGV名
/// </summary>
public string OccupiedAgvName { get; set; } = string.Empty;
public List<uint> CtuPointCodes { get; set; } = new List<uint>();
/// <summary>
/// 是否启用
/// </summary>
public bool Enabled { get; set; }
/// <summary>
/// 是否是共享区域
/// </summary>
public bool IsSharedArea { get; set; }
/// <summary>
/// 机器人类型
/// </summary>
public int RobotType { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Desc { get; set; } = "";
/// <summary>
/// 是否被占用
/// </summary>
/// <param name="agvName"></param>
/// <param name="pointCode"></param>
/// <returns></returns>
public bool IsOccupied(string agvName, int robotType)
{
if (!Enabled) return false;//未启用,认为未占用
if (CtuPointCodes == null || CtuPointCodes.Count == 0) return false;//没有地标,认为未占用
//if (IsSharedArea)
//{
//}
//else
{
if (!string.IsNullOrEmpty(OccupiedAgvName))
{
if (robotType == 1)
{
return true;
}
else
{
if (OccupiedAgvName.Equals(agvName))//被自己占用的认为未占用
{
return false;
}
else
{
return true;
}
}
}
}
return false;
}
public bool SetOccupied(RequestLimitInfo info)
{
if (info == null) return false;
OccupiedAgvName = info.AGVName;
RobotType = info.RobotType;
Desc = info.Desc;
LogUtil.info($"【{info.AGVName}】占用限制区【{info.AreaName}】【{info.Desc}】【{JsonHelper.SerializeObject(this)}】");
return true;
}
public bool ClearOccupied(ReleaseLimitInfo info)
{
if (info == null) return false;
if (info.RobotType == 1)//塔斯克
{
OccupiedAgvName = string.Empty;
RobotType = 0;
Desc = "";
LogUtil.info($"【{info.AGVName}】塔斯克 清除限制区完成 【{info.AreaName}】【{JsonHelper.SerializeObject(this)}】");
return true;
}
else
{
if (OccupiedAgvName.Equals(info.AGVName))
{
OccupiedAgvName = string.Empty;
RobotType = 0;
Desc = "";
LogUtil.info($"【{info.AGVName}】清除限制区完成【{info.AreaName}】【{JsonHelper.SerializeObject(this)}】");
return true;
}
}
return false;
}
public void Reset()
{
OccupiedAgvName = string.Empty;
RobotType = 0;
Desc = "";
LogUtil.info($"重置限制区【{Name}】状态");
}
public string[] ToDataGridData()
{
List<string> list = new List<string>()
{
Name,
Enabled?"启用":"关闭",
$"{OccupiedAgvName}",
$"{(IsSharedArea?"共享":"本地")}",
$"{string.Join(",",CtuPointCodes)}",
};
string type = "";
if (RobotType == 1)
{
type = "栈板AGV";
}
else if (RobotType == 2)
{
type = "半成品CTU";
}
else if (RobotType == 3)
{
type = "原材料CTU";
}
list.Add(type);
list.Add(Desc);
return list.ToArray();
}
}
public class RequestLimitInfo
{
public string AreaName { get; set; }
public int RobotType { get; set; }
public string AGVName { get; set; }
public string Desc { get; set; }
}
public class ReleaseLimitInfo
{
public int RobotType { get; set; }
public string AreaName { get; set; }
public string AGVName { get; set; }
}
}