LandMarks.cs
8.2 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CtuDeviceLib
{
public class LandMarks
{
/// <summary>
/// 所有地标
/// </summary>
static List<PointCode> _pointCodes = new List<PointCode>();
public static bool Load(string linefilePath)
{
if (!File.Exists(linefilePath))
{
LogUtil.error($"未找到路标配置路径:{linefilePath}");
return false;
}
LogUtil.info($"加载路标配置:{linefilePath}");
string[] lines = File.ReadAllLines(linefilePath);
List<PointCode> _tempPointCodes = new List<PointCode>();
for (int i = 1; i < lines.Length; i++)
{
string[] fields = lines[i].Split(',');
if (fields.Length < 10)
continue;
var landmark = new PointCode();
uint.TryParse(fields[0], out uint id);
landmark.Id = id;
landmark.Name = fields[1];
landmark.Type = (LandmarkType)Enum.Parse(typeof(LandmarkType), fields[2]);
landmark.CanTurning = bool.Parse(fields[3]);
string above = fields[4];
if (!string.IsNullOrEmpty(above))
{
landmark.Above = new LandmarkNeighboor();
}
if (!setNeighboringLand(landmark.Above, above, 0))
{
LogUtil.error($"加载异常:{above}");
return false;
}
string right = fields[5];
if (!string.IsNullOrEmpty(right))
{
landmark.Right = new LandmarkNeighboor();
}
if (!setNeighboringLand(landmark.Right, right, 90))
{
LogUtil.error(($"加载异常:{right}"));
return false;
}
string below = fields[6];
if (!string.IsNullOrEmpty(below))
{
landmark.Below = new LandmarkNeighboor();
}
if (!setNeighboringLand(landmark.Below, below, 180))
{
LogUtil.error($"加载异常:{below}");
return false;
}
string left = fields[7];
if (!string.IsNullOrEmpty(left))
{
landmark.Left = new LandmarkNeighboor();
}
if (!setNeighboringLand(landmark.Left, left, 270))
{
LogUtil.error($"加载异常:{left}");
return false;
}
landmark.X = int.Parse(fields[8]);
landmark.Y = int.Parse(fields[9]);
//landmark.Reserved = fields[8];
_tempPointCodes.Add(landmark);
}
_pointCodes = _tempPointCodes.ToList();
return true;
}
/// <summary>
/// 获取地标码信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static PointCode GetPointCode(uint id)
{
return _pointCodes.Find(s => s.Id == id);
}
public static List<PointCode> GetPointCodes()
{
return _pointCodes;
}
static short disBtwLandmark = ConfigHelper.Config.Get<short>(Mushiny.Common.Mushiny_ + "DefaultDisBtwLandmark", 1000);
static bool setNeighboringLand(LandmarkNeighboor landmark, string line, short angle = 0)
{
if (string.IsNullOrEmpty(line))
{
return true;
}
string[] tmp1 = line.Split('#');
landmark.Andle = angle;
landmark.Distance = disBtwLandmark;
if (tmp1.Length == 3)
{
var id = uint.Parse(tmp1[0]);
var dis = short.Parse(tmp1[1]);
var angl = short.Parse(tmp1[2]);
landmark.Id = id;
landmark.Distance = dis;
landmark.Andle = angl;
return true;
}
else if (tmp1.Length == 2)
{
var id = uint.Parse(tmp1[0]);
var dis = short.Parse(tmp1[1]);
landmark.Distance = dis;
landmark.Id = id;
return true;
}
else if (tmp1.Length == 1)
{
var id = uint.Parse(tmp1[0]);
landmark.Id = id;
return true;
}
return false;
}
}
/// <summary>
/// 地面点位编码
/// </summary>
public class PointCode
{
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 编号
/// </summary>
public uint Id { get; set; }
/// <summary>
/// 类型
/// </summary>
public LandmarkType Type { get; set; }
/// <summary>
/// 是否可转弯
/// </summary>
public bool CanTurning { get; set; }
/// <summary>
/// 上方路标
/// </summary>
public LandmarkNeighboor Above { get; set; }
/// <summary>
/// 右侧路标
/// </summary>
public LandmarkNeighboor Right { get; set; }
/// <summary>
/// 下方路标
/// </summary>
public LandmarkNeighboor Below { get; set; }
/// <summary>
/// 左侧路标
/// </summary>
public LandmarkNeighboor Left { get; set; }
public short GetDis(uint id)
{
if (Above != null && Above.Id == id)
{
return Above.Distance;
}
else if (Right != null && Right.Id == id)
{
return Right.Distance;
}
else if (Below != null && Below.Id == id)
{
return Below.Distance;
}
else if (Left != null && Left.Id == id) { return Left.Distance; }
else
{
return 0;
}
}
public short GetAngle(uint id)
{
if (Above != null && Above.Id == id)
{
return Above.Andle;
}
else if (Right != null && Right.Id == id)
{
return Right.Andle;
}
else if (Below != null && Below.Id == id)
{
return Below.Andle;
}
else if (Left != null && Left.Id == id) { return Left.Andle; }
else
{
return 0;
}
}
public int X { get; set; } = -1;
public int Y { get; set; } = -1;
/// <summary>
/// 预留
/// </summary>
public string Reserved { get; set; }
}
/// <summary>
/// 邻接地标
/// </summary>
public class LandmarkNeighboor
{
/// <summary>
/// 编号
/// </summary>
public uint Id { get; set; }
/// <summary>
/// 距离
/// </summary>
public short Distance { get; set; }
/// <summary>
/// 角度
/// </summary>
public short Andle { get; set; }
}
public enum LandmarkType
{
/// <summary>
/// 普通点
/// </summary>
None,
/// <summary>
/// 转弯点
/// </summary>
Turning,
/// <summary>
/// 货架点/巷道点
/// </summary>
Shelves,
/// <summary>
/// 设备对接点-默认车头0
/// </summary>
Docking_0,
/// <summary>
/// 设备对接点-默认车头90
/// </summary>
Docking_90,
/// <summary>
/// 设备对接点-默认车头180
/// </summary>
Docking_180,
/// <summary>
/// 设备对接点-默认车头270
/// </summary>
Docking_270,
}
}