1. 任务表添加字段

2. 任务下发部分代码
3. 其它
feature-flyModify
陈伟 2025-06-19 09:19:26 +08:00
parent 1e7b03d992
commit eecae62a74
6 changed files with 83 additions and 37 deletions

View File

@ -1,26 +1,51 @@
using ce.autofac.extension; using System.Text;
using ce.autofac.extension;
using Infrastructure.Cache; using Infrastructure.Cache;
using OpenAuth.WebApi;
using Quartz; using Quartz;
namespace OpenAuth.App.BaseApp.HostedService; namespace OpenAuth.App.BaseApp.HostedService;
/// <summary>
/// 离线去订阅
/// </summary>
public class GlobalSubscribe : IJob public class GlobalSubscribe : IJob
{ {
public Task Execute(IJobExecutionContext context) public async Task Execute(IJobExecutionContext context)
{ {
Console.WriteLine($"running !{DateTime.Now}"); Console.WriteLine($"running !{DateTime.Now}");
var redisCacheContext = context.JobDetail.JobDataMap.Get("redisCacheContext") as RedisCacheContext; var redisCacheContext = context.JobDetail.JobDataMap.Get("redisCacheContext") as RedisCacheContext;
var serviceProvider = context.JobDetail.JobDataMap.Get("serviceProvider") as IServiceProvider;
var mqttManager = serviceProvider.GetService(typeof(MqttClientManager)) as MqttClientManager;
/*var ioc = IocManager.Instance; /*var ioc = IocManager.Instance;
var redisCacheContext = IocManager.Instance.GetService<ICacheContext>();*/ var redisCacheContext = IocManager.Instance.GetService<ICacheContext>();*/
// todo 如果无人机不在线,则订阅 // todo 如果无人机不在线,则订阅
if (redisCacheContext == null) return Task.CompletedTask; if (redisCacheContext == null) return;
var keys = redisCacheContext.GetAllKeys("online:*"); var keys = redisCacheContext.GetAllKeys("online:*");
foreach (var redisKey in keys) foreach (var redisKey in keys)
{ {
// todo 取得sn值
// todo 取得设备信息
// todo
// todo 需要判断是不是要订阅,避免重复订阅
if (mqttManager != null)
await mqttManager.SubscribeAsync("thing/product/{gateway_sn}/services_reply", async (args) =>
{
var topic = args.ApplicationMessage.Topic;
var payload = args.ApplicationMessage.Payload;
var message = Encoding.UTF8.GetString(payload);
// todo 解析是否是需要的
// flighttask_prepare method
});
//statusSubscribe.subscribe(gateway);
//stateSubscribe.subscribe(gateway, true);
//osdSubscribe.subscribe(gateway, true);
//servicesSubscribe.subscribe(gateway);
//eventsSubscribe.subscribe(gateway, true);
//requestsSubscribe.subscribe(gateway);
//propertySetSubscribe.subscribe(gateway);
} }
// todo // todo
return Task.CompletedTask; return ;
} }
} }

View File

@ -42,12 +42,13 @@ namespace OpenAuth.App.HostedService
.WithIdentity("SubscribeJobTrigger", "GlobalSubscribe") .WithIdentity("SubscribeJobTrigger", "GlobalSubscribe")
.WithSimpleSchedule(x => { x.WithIntervalInSeconds(3).RepeatForever(); }) .WithSimpleSchedule(x => { x.WithIntervalInSeconds(3).RepeatForever(); })
.Build(); .Build();
_scheduler.Start(); var onceTrigger = TriggerBuilder.Create()
_scheduler.ScheduleJob(job, trigger); .WithIdentity("onceTrigger")
.WithSimpleSchedule(x => x.WithRepeatCount(0)).Build();
_scheduler.Start(cancellationToken);
_scheduler.ScheduleJob(job, trigger, cancellationToken);
var result = _openJobApp.StartAll(); var result = _openJobApp.StartAll();
return result; return result;
//return Task.CompletedTask;
} }
public Task StopAsync(CancellationToken cancellationToken) public Task StopAsync(CancellationToken cancellationToken)

View File

@ -607,13 +607,16 @@ namespace OpenAuth.App.ServiceApp
storage_capacity = 1000 storage_capacity = 1000
}; };
// todo 1. 查询上报断点 2. 断点续飞方法支持 // todo 1. 查询上报断点 2. 断点续飞方法支持
data.break_point = new if (false)
{ {
index = 1, // 断点序号 data.break_point = new
state = 1, // “0":"在航段上","1":"在航点上 {
progress = 1.0, // {"max":"1.0","min":"0"} index = 1, // 断点序号
wayline_id = "" // 航线id state = 1, // “0":"在航段上","1":"在航点上
}; progress = 1.0, // {"max":"1.0","min":"0"}
wayline_id = "" // 航线id
};
}
// 返航高度 {"max":1500,"min":20,"step":"","unit_name":"米 / m"} // 返航高度 {"max":1500,"min":20,"step":"","unit_name":"米 / m"}
data.rth_altitude = 150; // todo 取自任务 data.rth_altitude = 150; // todo 取自任务
// 返航高度模式 {"0":"智能高度","1":"设定高度"} // 返航高度模式 {"0":"智能高度","1":"设定高度"}
@ -627,7 +630,7 @@ namespace OpenAuth.App.ServiceApp
data.exit_wayline_when_rc_lost = 0; data.exit_wayline_when_rc_lost = 0;
// 航线精度类型 {"0":"GPS 任务","1":"高精度 RTK 任务"} // 航线精度类型 {"0":"GPS 任务","1":"高精度 RTK 任务"}
// 高精度 RTK 任务:飞行器起飞后会在空中等待 RTK 收敛后再执行任务,等待 RTK 收敛的过程中无法暂停任务。默认场景建议使用该模式。GPS 任务:飞行器无需等待 RTK 收敛便可以直接开始执行。精度要求不高的任务或对起飞时效性要求较高的任务建议使用该模式。 // 高精度 RTK 任务:飞行器起飞后会在空中等待 RTK 收敛后再执行任务,等待 RTK 收敛的过程中无法暂停任务。默认场景建议使用该模式。GPS 任务:飞行器无需等待 RTK 收敛便可以直接开始执行。精度要求不高的任务或对起飞时效性要求较高的任务建议使用该模式。
data.wayline_precision_type = task.PeriodicFormula; // todo 值来自任务 data.wayline_precision_type = task.WaylinePrecisionType; // 值来自任务
// 是否在模拟器中执行任务 todo 调试时使用 // 是否在模拟器中执行任务 todo 调试时使用
/*data.simulate_mission = new /*data.simulate_mission = new
{ {
@ -649,7 +652,6 @@ namespace OpenAuth.App.ServiceApp
if (data.task_type == 2) if (data.task_type == 2)
{ {
// 任务就绪条件 可选字段。条件任务(即 task_type 为2时必填其他类型任务会忽略该字段。下发条件任务后设备会定频检查 ready_conditions 是否全部满足,若全部满足则会有 flighttask_ready 事件通知。且设备端接收 flighttask_execute 指令时,也会检查任务的 ready_conditions 是否已全部满足。 // 任务就绪条件 可选字段。条件任务(即 task_type 为2时必填其他类型任务会忽略该字段。下发条件任务后设备会定频检查 ready_conditions 是否全部满足,若全部满足则会有 flighttask_ready 事件通知。且设备端接收 flighttask_execute 指令时,也会检查任务的 ready_conditions 是否已全部满足。
data.ready_conditions = new data.ready_conditions = new
{ {
// 可执行任务的飞行器电池电量百分比阈值,任务开始执行时的飞行器电量必须大于 // 可执行任务的飞行器电池电量百分比阈值,任务开始执行时的飞行器电量必须大于
@ -665,24 +667,6 @@ namespace OpenAuth.App.ServiceApp
request.SetData(data); request.SetData(data);
// 任务下发 // 任务下发
await _mqttClientManager.PublishAsync(topic, JsonConvert.SerializeObject(request)); await _mqttClientManager.PublishAsync(topic, JsonConvert.SerializeObject(request));
// todo 是否查询就绪任务 执行任务
await _mqttClientManager.PublishAsync(topic, JsonConvert.SerializeObject(request));
//thing/product/{gateway_sn}/services
var flightTaskExecuteTopic = string.Format(GatewayManager.FlightTaskPrepare, serialNo);
// todo
var flightTaskExecuteRequest = new TopicServicesRequest<object>
{
method = "flighttask_execute",
tid = "tid",
bid = "bid",
timestamp = DateTime.Now.Ticks,
data = new
{
flight_id = "" // todo
}
};
await _mqttClientManager.PublishAsync(flightTaskExecuteTopic,
JsonConvert.SerializeObject(flightTaskExecuteRequest));
} }
public async Task PendingFlyTask(string taskId) public async Task PendingFlyTask(string taskId)

View File

@ -74,6 +74,8 @@ namespace OpenAuth.Repository.Domain
public string AirLineId { get; set; } public string AirLineId { get; set; }
public long CreateId { get; set; } public long CreateId { get; set; }
public DateTime? CreateTime { get; set; } public DateTime? CreateTime { get; set; }
public int WaylinePrecisionType { get; set; }
// todo 关联openjob id // todo 关联openjob id
} }

View File

@ -81,7 +81,6 @@
<ItemGroup> <ItemGroup>
<Folder Include="Controllers\BaseControllers\Permission\" /> <Folder Include="Controllers\BaseControllers\Permission\" />
<Folder Include="Schedule\" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,35 @@
using System.Text;
using Quartz;
namespace OpenAuth.WebApi.boot;
public class ConfigSubscribe : IJob
{
private MqttClientManager mqttClientManager;
public void Subscribe()
{
// todo 订阅 "thing/product/{gateway_sn}/services_reply",
string gatewaySn = "8UUXN5400A079H";
mqttClientManager.SubscribeAsync($"thing/product/{gatewaySn}/services_reply", async (args) =>
{
// 确定主题 确定payload方法是 method
var topic = args.ApplicationMessage.Topic;
var payload = args.ApplicationMessage.Payload;
var message = Encoding.UTF8.GetString(payload);
});
}
public async Task Execute(IJobExecutionContext context)
{
var serviceProvider = context.JobDetail.JobDataMap.Get("serviceProvider") as IServiceProvider;
if (mqttClientManager != null) return;
if (serviceProvider != null)
{
mqttClientManager = serviceProvider.GetService(typeof(MqttClientManager)) as MqttClientManager;
Subscribe();
}
return;
}
}