IRobotCacheService.cs
5.57 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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Rcs.Domain.Entities;
namespace Rcs.Application.Services
{
/// <summary>
/// 机器人错误信息
/// @author zzy
/// </summary>
public class RobotError
{
public string ErrorType { get; set; } = string.Empty;
public string ErrorLevel { get; set; } = string.Empty;
public string ErrorDescription { get; set; } = string.Empty;
}
/// <summary>
/// 机器人缓存服务接口 - 负责机器人状态和位置的Redis缓存操作
/// @author zzy
/// </summary>
public interface IRobotCacheService
{
/// <summary>
/// 更新机器人状态到Redis(使用制造商+序列号作为唯一标识)
/// @author zzy
/// </summary>
Task UpdateStatusAsync(string manufacturer, string serialNumber, RobotStatus? status, OnlineStatus? online,
int? batteryLevel, bool? driving, bool? paused, bool? charging, OperatingMode? operatingMode, string? errors);
/// <summary>
/// 更新机器人位置到Redis(使用制造商+序列号作为唯一标识)
/// @author zzy
/// </summary>
Task UpdateLocationAsync(string manufacturer, string serialNumber, Guid? mapId, Guid? nodeId,
double? x, double? y, double? theta);
/// <summary>
/// 从Redis获取机器人状态(使用制造商+序列号作为唯一标识)
/// @author zzy
/// </summary>
Task<RobotStatusCache?> GetStatusAsync(string manufacturer, string serialNumber);
/// <summary>
/// 从Redis获取机器人位置(使用制造商+序列号作为唯一标识)
/// @author zzy
/// </summary>
Task<RobotLocationCache?> GetLocationAsync(string manufacturer, string serialNumber);
/// <summary>
/// 获取所有在线机器人标识(制造商:序列号)
/// @author zzy
/// </summary>
Task<IEnumerable<string>> GetOnlineRobotKeysAsync();
/// <summary>
/// 获取所有空闲机器人标识(制造商:序列号)
/// @author zzy
/// </summary>
Task<IEnumerable<string>> GetIdleRobotKeysAsync();
/// <summary>
/// 根据参数修改位置信息的值
/// </summary>
/// <param name="manufacturer"></param>
/// <param name="serialNumber"></param>
/// <param name="field"></param>
/// <param name="value"></param>
/// <returns></returns>
Task<bool> SetLocationValueAsync(string manufacturer, string serialNumber, string field, string value);
/// <summary>
/// 获取所有需要持久化的机器人状态数据(使用制造商+序列号作为唯一标识)
/// @author zzy
/// </summary>
Task<IEnumerable<(string Manufacturer, string SerialNumber, RobotStatusCache Status, RobotLocationCache Location)>> GetAllRobotCacheDataAsync();
/// <summary>
/// 从Redis获取机器人基础信息(使用制造商+序列号作为唯一标识)
/// @author zzy
/// </summary>
/// <param name="manufacturer">制造商</param>
/// <param name="serialNumber">序列号</param>
/// <returns>机器人基础信息缓存,不存在则返回null</returns>
Task<RobotBasicCache?> GetBasicAsync(string manufacturer, string serialNumber);
/// <summary>
/// 获取所有启用机器人的完整缓存数据(基础信息+状态+位置)
/// @author zzy
/// </summary>
Task<IEnumerable<(RobotBasicCache Basic, RobotStatusCache? Status, RobotLocationCache? Location)>> GetAllActiveRobotCacheAsync();
}
/// <summary>
/// 机器人状态缓存数据
/// @author zzy
/// </summary>
public class RobotStatusCache
{
public RobotStatus Status { get; set; }
public OnlineStatus Online { get; set; }
public int? BatteryLevel { get; set; }
public bool Driving { get; set; }
public bool Paused { get; set; }
public bool Charging { get; set; }
public OperatingMode OperatingMode { get; set; }
public List<RobotError>? Errors { get; set; }
public DateTime UpdatedAt { get; set; }
}
/// <summary>
/// 机器人位置缓存数据
/// @author zzy
/// </summary>
public class RobotLocationCache
{
public Guid? MapId { get; set; }
public Guid? NodeId { get; set; }
public double? X { get; set; }
public double? Y { get; set; }
public double? Theta { get; set; }
public List<List<double>>? Path { get; set; }
public DateTime UpdatedAt { get; set; }
}
/// <summary>
/// 机器人基础信息缓存数据
/// @author zzy
/// </summary>
public class RobotBasicCache
{
public string RobotId { get; set; } = string.Empty;
public string RobotCode { get; set; } = string.Empty;
public string RobotName { get; set; } = string.Empty;
public string RobotVersion { get; set; } = string.Empty;
public string ProtocolName { get; set; } = string.Empty;
public string ProtocolVersion { get; set; } = string.Empty;
public int ProtocolType { get; set; }
public string RobotManufacturer { get; set; } = string.Empty;
public string RobotSerialNumber { get; set; } = string.Empty;
public int RobotType { get; set; }
public string? IpAddress { get; set; }
public double CoordinateScale { get; set; }
public bool Active { get; set; }
}
}