在 AiVideo 中能看到图像
增加了在线状态同步逻辑
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using SHH.CameraDashboard.Services;
|
||||
using MessagePack;
|
||||
using SHH.Contracts;
|
||||
using SHH.ProcessLaunchers;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -30,9 +30,13 @@ namespace SHH.CameraDashboard
|
||||
StreamReceiverService.Instance.Start(6002);
|
||||
|
||||
// 启动指令服务 (Port 6001)
|
||||
CommandServer.Instance.Start(6001);
|
||||
|
||||
CommandServer.Instance.OnClientRegistered += SetupAutomaticConfiguration;
|
||||
CommandBusClient.Instance.Start(6001);
|
||||
CommandBusClient.Instance.OnServerRegistered += SetupAutomaticConfiguration;
|
||||
|
||||
//CommandServer.Instance.Start(6001);
|
||||
|
||||
//CommandServer.Instance.OnClientRegistered += SetupAutomaticConfiguration;
|
||||
|
||||
// 现在我们来配置启动
|
||||
|
||||
@@ -59,9 +63,10 @@ namespace SHH.CameraDashboard
|
||||
string serviceArgs = $"" +
|
||||
$"--pid {myPid} " +
|
||||
$"--appid \"CameraApp_01\" " +
|
||||
$"--uris \"127.0.0.1,6002,video,调试PC;\" " +
|
||||
$"--uris \"127.0.0.1,6003,video,调试PC;\" " +
|
||||
$"--uris \"127.0.0.1,6001,command,调试PC;\" " +
|
||||
$"--uris \"192.168.1.100,6002,video,大屏展示;\" " +
|
||||
$"--uris \"127.0.0.1,6004,command,调试PC;\" " +
|
||||
$"--uris \"127.0.0.1,6002,video,大屏展示;\" " +
|
||||
$"--mode 1 " +
|
||||
$"--ports \"5000,100\"";
|
||||
|
||||
@@ -71,7 +76,7 @@ namespace SHH.CameraDashboard
|
||||
Id = "CameraService", // 内部标识
|
||||
DisplayName = "视频接入服务", // UI显示名称
|
||||
// 请确保路径正确,建议用相对路径 AppDomain.CurrentDomain.BaseDirectory + "SHH.CameraService.exe"
|
||||
ExePath = @"D:\Codes\Ayay\SHH.CameraService\bin\Debug\net8.0\SHH.CameraService.exe",
|
||||
ExePath = @"E:\Codes2026\Ayay\SHH.CameraService\bin\Debug\net8.0\SHH.CameraService.exe",
|
||||
Arguments = serviceArgs, // ★★★ 核心:注入参数 ★★★
|
||||
StartupOrder = 1, // 优先级
|
||||
RestartDelayMs = 2000, // 崩溃后2秒重启
|
||||
@@ -90,6 +95,76 @@ namespace SHH.CameraDashboard
|
||||
mainWin.Show();
|
||||
}
|
||||
|
||||
private void SetupAutomaticConfiguration(RegisterPayload client)
|
||||
{
|
||||
Console.WriteLine($"[自动化] 新服务上线: {client.InstanceId}");
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(500);
|
||||
|
||||
// 1. 构建业务配置对象
|
||||
var cameraConfig = new CameraConfigDto
|
||||
{
|
||||
Id = 17798,
|
||||
Name = "206摄像头",
|
||||
Location = "404办公室",
|
||||
IpAddress = "172.16.41.88",
|
||||
Username = "admin",
|
||||
Password = "abcd1234",
|
||||
Port = 8000,
|
||||
ChannelIndex = 1,
|
||||
StreamType = 0,
|
||||
Brand = DeviceBrand.HikVision.GetHashCode(), // 对应 DeviceBrand 枚举
|
||||
RenderHandle = 0, // 初始化为0
|
||||
MainboardIp = "", // 留空
|
||||
MainboardPort = 0,
|
||||
RtspPath = ""
|
||||
};
|
||||
|
||||
// ★ 新增:一并带上订阅要求 ★
|
||||
cameraConfig.AutoSubscriptions = new List<CameraConfigSubscribeDto>
|
||||
{
|
||||
// 第一条:显示帧,要求 8 帧
|
||||
new CameraConfigSubscribeDto {
|
||||
AppId = "UI_Display",
|
||||
Type = 0,
|
||||
TargetFps = 8,
|
||||
Memo = "显示帧"
|
||||
},
|
||||
// 第二条:分析帧,要求 1 帧
|
||||
new CameraConfigSubscribeDto {
|
||||
AppId = "AI_Analysis",
|
||||
Type = 0,
|
||||
Memo = "分析帧",
|
||||
TargetFps = 1
|
||||
}
|
||||
};
|
||||
|
||||
// 2. 构造指令包
|
||||
var command = new CommandPayload
|
||||
{
|
||||
Protocol = ProtocolHeaders.Command,
|
||||
CmdCode = ProtocolHeaders.SyncCamera,
|
||||
TargetId = client.InstanceId,
|
||||
RequestId = Guid.NewGuid().ToString("N"),
|
||||
|
||||
// ★ 修正 1: 使用 JsonParams 属性名,并将对象序列化为 JSON 字符串 ★
|
||||
// 因为你的 DTO 定义 JsonParams 是 string 类型
|
||||
JsonParams = JsonHelper.Serialize(cameraConfig),
|
||||
|
||||
// ★ 修正 2: Timestamp 直接赋值 DateTime 对象 ★
|
||||
// 因为你的 DTO 定义 Timestamp 是 DateTime 类型
|
||||
Timestamp = DateTime.Now,
|
||||
|
||||
RequireAck = true
|
||||
};
|
||||
|
||||
// 3. 发送
|
||||
await CommandBusClient.Instance.SendInternalAsync(client.InstanceId, command);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在程序启动时订阅事件
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user