cloud sdk 部分代码
parent
063d8818f6
commit
834c0a4859
|
|
@ -0,0 +1,81 @@
|
||||||
|
namespace OpenAuth.WebApi;
|
||||||
|
|
||||||
|
public class CommonTopicRequest<T>
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The command is sent and the response is matched by the tid and bid fields in the message,
|
||||||
|
* and the reply should keep the tid and bid the same.
|
||||||
|
*/
|
||||||
|
public string Tid { get; set; }
|
||||||
|
|
||||||
|
public string Bid { get; set; }
|
||||||
|
|
||||||
|
public long? Timestamp { get; set; }
|
||||||
|
|
||||||
|
public T Data { get; set; }
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"CommonTopicRequest{{tid='{Tid}', bid='{Bid}', timestamp={Timestamp}, data={Data}}}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommonTopicRequest<T> SetTid(string tid)
|
||||||
|
{
|
||||||
|
Tid = tid;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommonTopicRequest<T> SetBid(string bid)
|
||||||
|
{
|
||||||
|
Bid = bid;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommonTopicRequest<T> SetTimestamp(long? timestamp)
|
||||||
|
{
|
||||||
|
Timestamp = timestamp;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommonTopicRequest<T> SetData(T data)
|
||||||
|
{
|
||||||
|
Data = data;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OsdTopicRequest<T> : CommonTopicRequest<T>
|
||||||
|
{
|
||||||
|
public string method { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public OsdTopicRequest<T> SetTid(string tid)
|
||||||
|
{
|
||||||
|
Tid = tid;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsdTopicRequest<T> SetBid(string bid)
|
||||||
|
{
|
||||||
|
Bid = bid;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsdTopicRequest<T> SetTimestamp(long? timestamp)
|
||||||
|
{
|
||||||
|
Timestamp = timestamp;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsdTopicRequest<T> SetData(T data)
|
||||||
|
{
|
||||||
|
Data = data;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsdTopicRequest<T> SetMethod(string method)
|
||||||
|
{
|
||||||
|
this.method = method;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace OpenAuth.WebApi.CloudSdk;
|
||||||
|
|
||||||
|
public class GatewayType
|
||||||
|
{
|
||||||
|
public string Dock = "1";
|
||||||
|
public string M300 = "2";
|
||||||
|
}
|
||||||
|
|
@ -55,7 +55,16 @@ public class MqttClientManager
|
||||||
_mqttClient.ApplicationMessageReceivedAsync += handler;
|
_mqttClient.ApplicationMessageReceivedAsync += handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task UnsubscribeAsync(string topic)
|
||||||
|
{
|
||||||
|
await _mqttClient.UnsubscribeAsync(topic, CancellationToken.None);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 向主题发布消息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="topic">主题</param>
|
||||||
|
/// <param name="message">json</param>
|
||||||
public async Task PublishAsync(string topic, string message)
|
public async Task PublishAsync(string topic, string message)
|
||||||
{
|
{
|
||||||
var mqttMsg = new MqttApplicationMessageBuilder()
|
var mqttMsg = new MqttApplicationMessageBuilder()
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
namespace OpenAuth.WebApi.CloudSdk;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 包含项目中使用的所有 MQTT 主题常量。
|
||||||
|
/// </summary>
|
||||||
|
public static class TopicConst
|
||||||
|
{
|
||||||
|
public const string BasicPre = "sys/";
|
||||||
|
public const string ThingModelPre = "thing/";
|
||||||
|
public const string Product = "product/";
|
||||||
|
public const string StatusSuffix = "/status";
|
||||||
|
public const string ReplySuffix = "_reply";
|
||||||
|
public const string StateSuffix = "/state";
|
||||||
|
public const string ServicesSuffix = "/services";
|
||||||
|
public const string OsdSuffix = "/osd";
|
||||||
|
public const string RequestsSuffix = "/requests";
|
||||||
|
public const string EventsSuffix = "/events";
|
||||||
|
public const string PropertySuffix = "/property";
|
||||||
|
public const string SetSuffix = "/set";
|
||||||
|
public const string RegexSn = "[A-Za-z0-9]+";
|
||||||
|
public const string Drc = "/drc";
|
||||||
|
public const string Up = "/up";
|
||||||
|
public const string Down = "/down";
|
||||||
|
}
|
||||||
|
|
@ -301,6 +301,18 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
|
|
||||||
// 航线任务在云端的 共享查看、下发执行、取消以及进度上报等功能。
|
// 航线任务在云端的 共享查看、下发执行、取消以及进度上报等功能。
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task ExecuteTask(string taskId)
|
||||||
|
{
|
||||||
|
// todo 取得任务信息
|
||||||
|
// todo 创建飞行任务
|
||||||
|
// todo 改变任务状态
|
||||||
|
// todo
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 测试
|
||||||
|
/// </summary>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task Test()
|
public async Task Test()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue