Context.cs
2.8 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
using Common;
using DeviceLib.Model.AGV;
using System;
using System.Threading;
namespace DeviceLib.BLL
{
public class Context
{
static Thread threadRobotCall;
static int interval = 1000;
static bool isLoad = false;
static bool loop = false;
/// <summary>
/// 加载配置
/// </summary>
public static void Load()
{
isLoad = false;
RobotManager.Load();
NodeManager.Load();
MissionManager.Load();
NodeManager.InitServer();
isLoad = true;
LogUtil.Info("程序配置加载成功!");
}
/// <summary>
/// 启动
/// </summary>
public static void Start()
{
loop = true;
threadRobotCall = new Thread(RobotCall);
threadRobotCall.IsBackground = true;
threadRobotCall.Start();
NodeManager.StartServer();
ServiceManager.Start();
}
/// <summary>
/// 停止
/// </summary>
public static void Stop()
{
loop = false;
NodeManager.StopServer();
ServiceManager.Stop();
}
/// <summary>
/// agv占用节点
/// </summary>
/// <param name="robotId">机器人编号</param>
/// <param name="nodeName">节点名</param>
public static void SetNodeOccupied(int robotId, string nodeName = "")
{
if (nodeName.Equals(""))
{
foreach (var item in NodeManager.GetClientNodes())
{
if (item.occupiedAgv.Equals(robotId))
item.occupiedAgv = 0;
}
}
else
{
ClientNode clientNode = NodeManager.GetClientNodeByName(nodeName);
if (clientNode != null)
clientNode.occupiedAgv = robotId;
}
}
static void RobotCall()
{
while (loop)
{
try
{
if (!isLoad)
continue;
foreach (var item in RobotManager.GetAllRobots())
{
// if (!item?.status?.is_online ?? false) continue;
JobManager.CheckResend(item);
JobManager.GetNewJob(item);
JobManager.Execute(item);
RobotManager.UploadState(item);
}
Thread.Sleep(interval);
}
catch (Exception ex)
{
LogUtil.Error("RobotCall", ex);
}
}
}
}
}