-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepetierMqttClient.cs
73 lines (56 loc) · 2.47 KB
/
RepetierMqttClient.cs
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
using MQTTnet.Client;
using MQTTnet.Packets;
using RepetierSharp.Models.Commands;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace RepetierSharp.RepetierMqtt
{
public partial class RepetierMqttClient
{
/// <summary>
/// Mapping for events -> topics
/// Used to determine where to publish the data of an event
/// </summary>
private Dictionary<string, MqttTopicFilter> EventTopics { get; set; } = new Dictionary<string, MqttTopicFilter>();
/// <summary>
/// Mapping for events -> topics
/// Used to determine where to publish the data of an event
/// </summary>
private Dictionary<string, Dictionary<string, MqttTopicFilter>> PrinterEventTopics { get; set; } = new Dictionary<string, Dictionary<string, MqttTopicFilter>>();
/// <summary>
/// Mapping for command -> topics
/// Used to determine where to publish the response data of a sent command
/// </summary>
private Dictionary<string, MqttTopicFilter> CommandResponseTopics { get; set; } = new Dictionary<string, MqttTopicFilter>();
public RepetierConnection RepetierConnection { get; private set; }
public string BaseTopic { get; set; }
private IMqttClient MqttClient { get; set; }
private MqttClientOptions MqttClientOptions { get; set; }
private uint ReconnectDelay { get; set; } = 3000;
/// <summary>
/// Topic -> Command to execute
/// </summary>
private Dictionary<string, ICommandData> CommandMapping { get; set; } = new Dictionary<string, ICommandData>();
/// <summary>
/// Topic for starting / uploading gcode.
/// Expected payload: UploadGCodeCommand
/// </summary>
public MqttTopicFilter UploadGCodeTopic { get; private set; }
/// <summary>
/// Topic for executing repetier commands.
/// Expected payload depending on command.
/// </summary>
public MqttTopicFilter ExecuteCommandTopic { get; private set; }
public MqttTopicFilter DefaultResponseTopic { get; private set; }
public MqttTopicFilter DefaultEventTopic { get; private set; }
private RepetierMqttClient() { }
public Task<MqttClientConnectResult> Connect()
{
return MqttClient.ConnectAsync(MqttClientOptions);
}
public Task Disconnect()
{
return MqttClient.DisconnectAsync();
}
}
}