Compare commits
13 Commits
dpp
...
11ef4dfba6
| Author | SHA1 | Date | |
|---|---|---|---|
| 11ef4dfba6 | |||
| bbde060d11 | |||
| 58378851bb | |||
| ae50ba3b9f | |||
| d2508f6484 | |||
| aff9da2a60 | |||
|
|
e0ac21d141 | ||
| 8396b7aaea | |||
|
|
a331494fde | ||
|
|
e86cd5464e | ||
|
|
04b136117d | ||
|
|
5c87204ef6 | ||
| 35647d21bb |
@@ -303,11 +303,8 @@ async function generateApiClient(): Promise<void> {
|
||||
async function generateSignalRClient(): Promise<void> {
|
||||
console.log("Generating SignalR TypeScript client...");
|
||||
try {
|
||||
// TypedSignalR.Client.TypeScript.Analyzer 会在编译时自动生成客户端
|
||||
// 我们只需要确保服务器项目构建一次即可生成 TypeScript 客户端
|
||||
const { stdout, stderr } = await execAsync(
|
||||
"dotnet build --configuration Release",
|
||||
{ cwd: "./server" }
|
||||
"dotnet tsrts --project ./server/server.csproj --output ./src/",
|
||||
);
|
||||
if (stdout) console.log(stdout);
|
||||
if (stderr) console.error(stderr);
|
||||
|
||||
@@ -35,57 +35,133 @@ public class NumberTest
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试 BytesToUInt64 的正常与异常情况
|
||||
/// 测试 BytesToUInt64 的正常与异常情况,覆盖不同参数组合
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Test_BytesToUInt64()
|
||||
{
|
||||
// 正常大端
|
||||
// 正常大端(isLowNumHigh=false)
|
||||
var bytes = new byte[] { 0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x01 };
|
||||
var result = Number.BytesToUInt64((byte[])bytes.Clone(), false);
|
||||
var result = Number.BytesToUInt64((byte[])bytes.Clone());
|
||||
Assert.True(result.IsSuccessful);
|
||||
Assert.Equal(0x12345678ABCDEF01UL, result.Value);
|
||||
|
||||
// 正常小端
|
||||
// 正常小端(isLowNumHigh=true)
|
||||
var bytes2 = new byte[] { 0x01, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12 };
|
||||
var result2 = Number.BytesToUInt64((byte[])bytes2.Clone(), true);
|
||||
Assert.True(result2.IsSuccessful);
|
||||
Assert.Equal(0x12345678ABCDEF01UL, result2.Value);
|
||||
|
||||
// 异常:长度超限
|
||||
var result3 = Number.BytesToUInt64(new byte[9], false);
|
||||
Assert.False(result3.IsSuccessful);
|
||||
// 长度不足8字节(numLength=4),大端
|
||||
var bytes3 = new byte[] { 0x12, 0x34, 0x56, 0x78 };
|
||||
var result3 = Number.BytesToUInt64((byte[])bytes3.Clone(), 0, 4, false);
|
||||
Assert.True(result3.IsSuccessful);
|
||||
Assert.Equal(0x1234567800000000UL, result3.Value);
|
||||
|
||||
// 异常:不足8字节
|
||||
var result4 = Number.BytesToUInt64(new byte[] { 0x01, 0x02 }, false);
|
||||
Assert.False(result4.IsSuccessful); // BitConverter.ToUInt64 需要8字节
|
||||
// 长度不足8字节(numLength=4),小端
|
||||
var bytes4 = new byte[] { 0x78, 0x56, 0x34, 0x12 };
|
||||
var result4 = Number.BytesToUInt64((byte[])bytes4.Clone(), 0, 4, true);
|
||||
Assert.True(result4.IsSuccessful);
|
||||
Assert.Equal(0x12345678UL, result4.Value);
|
||||
|
||||
// numLength=0
|
||||
var bytes5 = new byte[] { 0x12, 0x34, 0x56, 0x78 };
|
||||
var result5 = Number.BytesToUInt64((byte[])bytes5.Clone(), 0, 0, false);
|
||||
Assert.True(result5.IsSuccessful);
|
||||
Assert.Equal(0UL, result5.Value);
|
||||
|
||||
// offset测试
|
||||
var bytes6 = new byte[] { 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x01 };
|
||||
var result6 = Number.BytesToUInt64(bytes6, 2, 8, false);
|
||||
Assert.True(result6.IsSuccessful);
|
||||
Assert.Equal(0x12345678ABCDEF01UL, result6.Value);
|
||||
|
||||
// numLength超限(>8),应返回异常
|
||||
var bytes7 = new byte[9];
|
||||
var result7 = Number.BytesToUInt64(bytes7, 0, 9, false);
|
||||
Assert.False(result7.IsSuccessful);
|
||||
|
||||
// offset+numLength超限
|
||||
var bytes8 = new byte[] { 0x01, 0x02, 0x03, 0x04 };
|
||||
var result8 = Number.BytesToUInt64(bytes8, 2, 4, false);
|
||||
Assert.True(result8.IsSuccessful);
|
||||
Assert.Equal(0x0304000000000000UL, result8.Value);
|
||||
|
||||
// bytes长度不足offset+numLength
|
||||
var bytes9 = new byte[] { 0x01, 0x02 };
|
||||
var result9 = Number.BytesToUInt64(bytes9, 1, 2, true);
|
||||
Assert.True(result9.IsSuccessful);
|
||||
Assert.Equal(0x02UL, result9.Value);
|
||||
|
||||
// 空数组
|
||||
var result10 = Number.BytesToUInt64(new byte[0], 0, 0, false);
|
||||
Assert.True(result10.IsSuccessful);
|
||||
Assert.Equal(0UL, result10.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试 BytesToUInt32 的正常与异常情况
|
||||
/// 测试 BytesToUInt32 的正常与异常情况,覆盖不同参数组合
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Test_BytesToUInt32()
|
||||
{
|
||||
// 正常大端
|
||||
// 正常大端(isLowNumHigh=false)
|
||||
var bytes = new byte[] { 0x12, 0x34, 0x56, 0x78 };
|
||||
var result = Number.BytesToUInt32((byte[])bytes.Clone(), false);
|
||||
var result = Number.BytesToUInt32((byte[])bytes.Clone());
|
||||
Assert.True(result.IsSuccessful);
|
||||
Assert.Equal(0x12345678U, result.Value);
|
||||
|
||||
// 正常小端
|
||||
// 正常小端(isLowNumHigh=true)
|
||||
var bytes2 = new byte[] { 0x78, 0x56, 0x34, 0x12 };
|
||||
var result2 = Number.BytesToUInt32((byte[])bytes2.Clone(), true);
|
||||
Assert.True(result2.IsSuccessful);
|
||||
Assert.Equal(0x12345678U, result2.Value);
|
||||
|
||||
// 异常:长度超限
|
||||
var result3 = Number.BytesToUInt32(new byte[5], false);
|
||||
Assert.False(result3.IsSuccessful);
|
||||
// 长度不足4字节(numLength=2),大端
|
||||
var bytes3 = new byte[] { 0x12, 0x34 };
|
||||
var result3 = Number.BytesToUInt32((byte[])bytes3.Clone(), 0, 2, false);
|
||||
Assert.True(result3.IsSuccessful);
|
||||
Assert.Equal(0x12340000U, result3.Value);
|
||||
|
||||
// 异常:不足4字节
|
||||
var result4 = Number.BytesToUInt32(new byte[] { 0x01, 0x02 }, false);
|
||||
Assert.False(result4.IsSuccessful); // BitConverter.ToUInt32 需要4字节
|
||||
// 长度不足4字节(numLength=2),小端
|
||||
var bytes4 = new byte[] { 0x34, 0x12 };
|
||||
var result4 = Number.BytesToUInt32((byte[])bytes4.Clone(), 0, 2, true);
|
||||
Assert.True(result4.IsSuccessful);
|
||||
Assert.Equal(0x1234U, result4.Value);
|
||||
|
||||
// numLength=0
|
||||
var bytes5 = new byte[] { 0x12, 0x34, 0x56, 0x78 };
|
||||
var result5 = Number.BytesToUInt32((byte[])bytes5.Clone(), 0, 0, false);
|
||||
Assert.True(result5.IsSuccessful);
|
||||
Assert.Equal(0U, result5.Value);
|
||||
|
||||
// offset测试
|
||||
var bytes6 = new byte[] { 0x00, 0x00, 0x12, 0x34, 0x56, 0x78 };
|
||||
var result6 = Number.BytesToUInt32(bytes6, 2, 4, false);
|
||||
Assert.True(result6.IsSuccessful);
|
||||
Assert.Equal(0x12345678U, result6.Value);
|
||||
|
||||
// numLength超限(>4),应返回异常
|
||||
var bytes7 = new byte[5];
|
||||
var result7 = Number.BytesToUInt32(bytes7, 0, 5, false);
|
||||
Assert.False(result7.IsSuccessful);
|
||||
|
||||
// offset+numLength超限
|
||||
var bytes8 = new byte[] { 0x01, 0x02, 0x03, 0x04 };
|
||||
var result8 = Number.BytesToUInt32(bytes8, 2, 2, false);
|
||||
Assert.True(result8.IsSuccessful);
|
||||
Assert.Equal(0x03040000U, result8.Value);
|
||||
|
||||
// bytes长度不足offset+numLength
|
||||
var bytes9 = new byte[] { 0x01, 0x02 };
|
||||
var result9 = Number.BytesToUInt32(bytes9, 1, 1, true);
|
||||
Assert.True(result9.IsSuccessful);
|
||||
Assert.Equal(0x02U, result9.Value);
|
||||
|
||||
// 空数组
|
||||
var result10 = Number.BytesToUInt32(new byte[0], 0, 0, false);
|
||||
Assert.True(result10.IsSuccessful);
|
||||
Assert.Equal(0U, result10.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -283,4 +359,28 @@ public class NumberTest
|
||||
var reversed2 = Number.ReverseBits(new byte[0]);
|
||||
Assert.Empty(reversed2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试 GetLength
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Test_GetLength()
|
||||
{
|
||||
Assert.Equal(5, Number.GetLength(12345));
|
||||
Assert.Equal(4, Number.GetLength(-123));
|
||||
Assert.Equal(1, Number.GetLength(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试 IntPow
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Test_IntPow()
|
||||
{
|
||||
Assert.Equal(8, Number.IntPow(2, 3));
|
||||
Assert.Equal(1, Number.IntPow(5, 0));
|
||||
Assert.Equal(0, Number.IntPow(0, 5));
|
||||
Assert.Equal(7, Number.IntPow(7, 1));
|
||||
Assert.Equal(81, Number.IntPow(3, 4));
|
||||
}
|
||||
}
|
||||
|
||||
99
server.test/ProgressTrackerTest.cs
Normal file
99
server.test/ProgressTrackerTest.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Moq;
|
||||
using server.Hubs;
|
||||
using server.Services;
|
||||
|
||||
public class ProgressTrackerTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task Test_ProgressReporter_Basic()
|
||||
{
|
||||
int reportedValue = -1;
|
||||
var reporter = new ProgressReporter(async v => { reportedValue = v; await Task.CompletedTask; }, 0, 100, 10);
|
||||
|
||||
// Report
|
||||
reporter.Report(50);
|
||||
Assert.Equal(50, reporter.Progress);
|
||||
Assert.Equal(ProgressStatus.InProgress, reporter.Status);
|
||||
Assert.Equal(50, reportedValue);
|
||||
|
||||
// Increase by step
|
||||
reporter.Increase();
|
||||
Assert.Equal(60, reporter.Progress);
|
||||
|
||||
// Increase by value
|
||||
reporter.Increase(20);
|
||||
Assert.Equal(80, reporter.Progress);
|
||||
|
||||
// Finish
|
||||
reporter.Finish();
|
||||
Assert.Equal(ProgressStatus.Completed, reporter.Status);
|
||||
Assert.Equal(100, reporter.Progress);
|
||||
|
||||
// Cancel
|
||||
reporter = new ProgressReporter(async v => { reportedValue = v; await Task.CompletedTask; }, 0, 100, 10);
|
||||
reporter.Cancel();
|
||||
Assert.Equal(ProgressStatus.Canceled, reporter.Status);
|
||||
Assert.Equal("User Cancelled", reporter.ErrorMessage);
|
||||
|
||||
// Error
|
||||
reporter = new ProgressReporter(async v => { reportedValue = v; await Task.CompletedTask; }, 0, 100, 10);
|
||||
reporter.Error("Test Error");
|
||||
Assert.Equal(ProgressStatus.Failed, reporter.Status);
|
||||
Assert.Equal("Test Error", reporter.ErrorMessage);
|
||||
|
||||
// CreateChild
|
||||
var parent = new ProgressReporter(async v => { await Task.CompletedTask; }, 10, 100, 5);
|
||||
var child = parent.CreateChild(50, 5);
|
||||
Assert.Equal(ProgressStatus.Pending, child.Status);
|
||||
Assert.NotNull(child);
|
||||
|
||||
// Child Increase
|
||||
child.Increase();
|
||||
Assert.Equal(ProgressStatus.InProgress, child.Status);
|
||||
Assert.Equal(20, child.ProgressPercent);
|
||||
Assert.Equal(20, parent.Progress);
|
||||
|
||||
// Child Complete
|
||||
child.Finish();
|
||||
Assert.Equal(ProgressStatus.Completed, child.Status);
|
||||
Assert.Equal(100, child.ProgressPercent);
|
||||
Assert.Equal(60, parent.Progress);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test_ProgressTrackerService_Basic()
|
||||
{
|
||||
// Mock SignalR HubContext
|
||||
var mockHubContext = new Mock<IHubContext<ProgressHub, IProgressReceiver>>();
|
||||
var service = new ProgressTrackerService(mockHubContext.Object);
|
||||
|
||||
// CreateTask
|
||||
var (taskId, reporter) = service.CreateTask();
|
||||
Assert.NotNull(taskId);
|
||||
Assert.NotNull(reporter);
|
||||
|
||||
// GetReporter
|
||||
var optReporter = service.GetReporter(taskId);
|
||||
Assert.True(optReporter.HasValue);
|
||||
Assert.Equal(reporter, optReporter.Value);
|
||||
|
||||
// GetProgressStatus
|
||||
var optStatus = service.GetProgressStatus(taskId);
|
||||
Assert.True(optStatus.HasValue);
|
||||
Assert.Equal(ProgressStatus.Pending, optStatus.Value);
|
||||
|
||||
// BindTask
|
||||
var bindResult = service.BindTask(taskId, "conn1");
|
||||
Assert.True(bindResult);
|
||||
|
||||
// CancelTask
|
||||
var cancelResult = service.CancelTask(taskId);
|
||||
Assert.True(cancelResult);
|
||||
|
||||
// After cancel, status should be Cancelled
|
||||
var optStatus2 = service.GetProgressStatus(taskId);
|
||||
Assert.True(optStatus2.HasValue);
|
||||
Assert.Equal(ProgressStatus.Canceled, optStatus2.Value);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -145,6 +145,12 @@ try
|
||||
// 添加 HTTP 视频流服务
|
||||
builder.Services.AddSingleton<HttpVideoStreamService>();
|
||||
builder.Services.AddHostedService(provider => provider.GetRequiredService<HttpVideoStreamService>());
|
||||
builder.Services.AddSingleton<HttpHdmiVideoStreamService>();
|
||||
builder.Services.AddHostedService(provider => provider.GetRequiredService<HttpHdmiVideoStreamService>());
|
||||
|
||||
// 添加进度跟踪服务
|
||||
builder.Services.AddSingleton<ProgressTrackerService>();
|
||||
builder.Services.AddHostedService(provider => provider.GetRequiredService<ProgressTrackerService>());
|
||||
|
||||
// Application Settings
|
||||
var app = builder.Build();
|
||||
@@ -215,7 +221,8 @@ try
|
||||
|
||||
// Router
|
||||
app.MapControllers();
|
||||
app.MapHub<server.Hubs.JtagHub.JtagHub>("hubs/JtagHub");
|
||||
app.MapHub<server.Hubs.JtagHub>("hubs/JtagHub");
|
||||
app.MapHub<server.Hubs.ProgressHub>("hubs/ProgressHub");
|
||||
|
||||
// Setup Program
|
||||
MsgBus.Init();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<SpaRoot>../</SpaRoot>
|
||||
<SpaProxyServerUrl>http://localhost:5173</SpaProxyServerUrl>
|
||||
<SpaProxyLaunchCommand>npm run dev</SpaProxyLaunchCommand>
|
||||
<NoWarn>CS1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -24,7 +25,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.OpenApi" Version="1.6.23" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NLog" Version="5.4.0" />
|
||||
<PackageReference Include="NLog" Version="5.4.0" />
|
||||
<PackageReference Include="NLog.Web.AspNetCore" Version="5.4.0" />
|
||||
<PackageReference Include="NSwag.AspNetCore" Version="14.3.0" />
|
||||
<PackageReference Include="NSwag.CodeGeneration.TypeScript" Version="14.4.0" />
|
||||
|
||||
@@ -78,6 +78,56 @@ public class Number
|
||||
return arr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 二进制字节数组转成64bits整数
|
||||
/// </summary>
|
||||
/// <param name="bytes">二进制字节数组</param>
|
||||
/// <param name="offset">字节数组偏移量</param>
|
||||
/// <param name="numLength">字节数组长度</param>
|
||||
/// <param name="isLowNumHigh">是否高位在数组索引低</param>
|
||||
/// <returns>整数</returns>
|
||||
public static Result<UInt64> BytesToUInt64(byte[] bytes, int offset = 0, int numLength = 8, bool isLowNumHigh = false)
|
||||
{
|
||||
if (bytes.Length < offset)
|
||||
{
|
||||
return new(new ArgumentException($"The Length of bytes is less than offset"));
|
||||
}
|
||||
|
||||
if (numLength > 8)
|
||||
{
|
||||
return new(new ArgumentException($"The Length of bytes is greater than 8"));
|
||||
}
|
||||
|
||||
if (numLength <= 0) return 0;
|
||||
|
||||
try
|
||||
{
|
||||
byte[] numBytes = new byte[8]; // 8字节
|
||||
int copyLen = Math.Min(numLength, bytes.Length - offset);
|
||||
|
||||
if (isLowNumHigh)
|
||||
{
|
||||
// 小端:拷贝到低位
|
||||
Buffer.BlockCopy(bytes, offset, numBytes, 0, copyLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 大端:拷贝到高位
|
||||
byte[] temp = new byte[copyLen];
|
||||
Buffer.BlockCopy(bytes, offset, temp, 0, copyLen);
|
||||
Array.Reverse(temp);
|
||||
Buffer.BlockCopy(temp, 0, numBytes, 8 - copyLen, copyLen);
|
||||
}
|
||||
|
||||
UInt64 num = BitConverter.ToUInt64(numBytes, 0);
|
||||
return num;
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
return new(error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 二进制字节数组转成64bits整数
|
||||
/// </summary>
|
||||
@@ -86,25 +136,78 @@ public class Number
|
||||
/// <returns>整数</returns>
|
||||
public static Result<UInt64> BytesToUInt64(byte[] bytes, bool isLowNumHigh = false)
|
||||
{
|
||||
if (bytes.Length > 8)
|
||||
return BytesToUInt64(bytes, 0, 8, isLowNumHigh);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 二进制字节数组转成64bits整数
|
||||
/// </summary>
|
||||
/// <param name="bytes">二进制字节数组</param>
|
||||
/// <returns>整数</returns>
|
||||
public static Result<UInt64> BytesToUInt64(byte[] bytes)
|
||||
{
|
||||
return BytesToUInt64(bytes, 0, 8, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 二进制字节数组转成32bits整数
|
||||
/// </summary>
|
||||
/// <param name="bytes">二进制字节数组</param>
|
||||
/// <param name="offset">字节数组偏移量</param>
|
||||
/// <param name="numLength">整形所占字节数组长度</param>
|
||||
/// <param name="isLowNumHigh">是否高位在数组索引低</param>
|
||||
/// <returns>整数</returns>
|
||||
public static Result<UInt32> BytesToUInt32(byte[] bytes, int offset = 0, int numLength = 4, bool isLowNumHigh = false)
|
||||
{
|
||||
if (bytes.Length < offset)
|
||||
{
|
||||
return new(new ArgumentException(
|
||||
"Unsigned long number can't over 8 bytes(64 bits).",
|
||||
nameof(bytes)
|
||||
));
|
||||
return new(new ArgumentException($"The Length of bytes is less than offset"));
|
||||
}
|
||||
|
||||
UInt64 num = 0;
|
||||
int len = bytes.Length;
|
||||
if (numLength > 4)
|
||||
{
|
||||
return new(new ArgumentException($"The Length of bytes is greater than 4"));
|
||||
}
|
||||
|
||||
if (bytes.Length < offset)
|
||||
{
|
||||
return new(new ArgumentException($"The Length of bytes is less than offset"));
|
||||
}
|
||||
|
||||
if (numLength > 4)
|
||||
{
|
||||
return new(new ArgumentException($"The Length of bytes is greater than 4"));
|
||||
}
|
||||
|
||||
if (numLength <= 0) return 0;
|
||||
|
||||
try
|
||||
{
|
||||
if (!isLowNumHigh)
|
||||
{
|
||||
Array.Reverse(bytes);
|
||||
}
|
||||
num = BitConverter.ToUInt64(bytes, 0);
|
||||
byte[] numBytes = new byte[4]; // 4字节
|
||||
int copyLen = Math.Min(numLength, bytes.Length - offset);
|
||||
if (copyLen < 0) copyLen = 0;
|
||||
|
||||
if (isLowNumHigh)
|
||||
{
|
||||
// 小端:拷贝到低位
|
||||
if (copyLen > 0)
|
||||
{
|
||||
Buffer.BlockCopy(bytes, offset, numBytes, 0, copyLen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 大端:拷贝到高位
|
||||
if (copyLen > 0)
|
||||
{
|
||||
byte[] temp = new byte[copyLen];
|
||||
Buffer.BlockCopy(bytes, offset, temp, 0, copyLen);
|
||||
Array.Reverse(temp);
|
||||
Buffer.BlockCopy(temp, 0, numBytes, 4 - copyLen, copyLen);
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 num = BitConverter.ToUInt32(numBytes, 0);
|
||||
return num;
|
||||
}
|
||||
catch (Exception error)
|
||||
@@ -121,32 +224,17 @@ public class Number
|
||||
/// <returns>整数</returns>
|
||||
public static Result<UInt32> BytesToUInt32(byte[] bytes, bool isLowNumHigh = false)
|
||||
{
|
||||
if (bytes.Length > 4)
|
||||
{
|
||||
return new(new ArgumentException(
|
||||
"Unsigned long number can't over 4 bytes(32 bits).",
|
||||
nameof(bytes)
|
||||
));
|
||||
}
|
||||
|
||||
UInt32 num = 0;
|
||||
int len = bytes.Length;
|
||||
|
||||
try
|
||||
{
|
||||
if (!isLowNumHigh)
|
||||
{
|
||||
Array.Reverse(bytes);
|
||||
}
|
||||
num = BitConverter.ToUInt32(bytes, 0);
|
||||
|
||||
return num;
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
return new(error);
|
||||
}
|
||||
return BytesToUInt32(bytes, 0, 4, isLowNumHigh);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 二进制字节数组转成32bits整数
|
||||
/// </summary>
|
||||
/// <param name="bytes">二进制字节数组</param>
|
||||
/// <returns>整数</returns>
|
||||
public static Result<UInt32> BytesToUInt32(byte[] bytes)
|
||||
{
|
||||
return BytesToUInt32(bytes, 0, 4, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -348,4 +436,37 @@ public class Number
|
||||
}
|
||||
return dstBytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数字的长度
|
||||
/// </summary>
|
||||
/// <param name="number">数字</param>
|
||||
/// <returns>数字的长度</returns>
|
||||
public static int GetLength(int number)
|
||||
{
|
||||
// 将整数转换为字符串
|
||||
string numberString = number.ToString();
|
||||
|
||||
// 返回字符串的长度
|
||||
return numberString.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算整形的幂
|
||||
/// </summary>
|
||||
/// <param name="x">底数</param>
|
||||
/// <param name="pow">幂</param>
|
||||
/// <returns>计算结果</returns>
|
||||
public static int IntPow(int x, int pow)
|
||||
{
|
||||
int ret = 1;
|
||||
while (pow != 0)
|
||||
{
|
||||
if ((pow & 1) == 1)
|
||||
ret *= x;
|
||||
x *= x;
|
||||
pow >>= 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
97
server/src/Controllers/HdmiVideoStreamController.cs
Normal file
97
server/src/Controllers/HdmiVideoStreamController.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Security.Claims;
|
||||
using server.Services;
|
||||
using Database;
|
||||
|
||||
namespace server.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
[EnableCors("Users")]
|
||||
public class HdmiVideoStreamController : ControllerBase
|
||||
{
|
||||
private readonly HttpHdmiVideoStreamService _videoStreamService;
|
||||
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
public HdmiVideoStreamController(HttpHdmiVideoStreamService videoStreamService)
|
||||
{
|
||||
_videoStreamService = videoStreamService;
|
||||
}
|
||||
|
||||
// 管理员获取所有板子的 endpoints
|
||||
[HttpGet("AllEndpoints")]
|
||||
[Authorize("Admin")]
|
||||
public ActionResult<List<HdmiVideoStreamEndpoint>> GetAllEndpoints()
|
||||
{
|
||||
var endpoints = _videoStreamService.GetAllVideoEndpoints();
|
||||
if (endpoints == null)
|
||||
return NotFound("No boards found.");
|
||||
return Ok(endpoints);
|
||||
}
|
||||
|
||||
// 用户获取自己板子的 endpoint
|
||||
[HttpGet("MyEndpoint")]
|
||||
[Authorize]
|
||||
public ActionResult<HdmiVideoStreamEndpoint> GetMyEndpoint()
|
||||
{
|
||||
var userName = User.FindFirstValue(ClaimTypes.Name);
|
||||
if (string.IsNullOrEmpty(userName))
|
||||
return Unauthorized("User name not found in claims.");
|
||||
|
||||
var db = new AppDataConnection();
|
||||
if (db == null)
|
||||
return NotFound("Database connection failed.");
|
||||
|
||||
var userRet = db.GetUserByName(userName);
|
||||
if (!userRet.IsSuccessful || !userRet.Value.HasValue)
|
||||
return NotFound("User not found.");
|
||||
|
||||
var user = userRet.Value.Value;
|
||||
var boardId = user.BoardID;
|
||||
if (boardId == Guid.Empty)
|
||||
return NotFound("No board bound to this user.");
|
||||
|
||||
var boardRet = db.GetBoardByID(boardId);
|
||||
if (!boardRet.IsSuccessful || !boardRet.Value.HasValue)
|
||||
return NotFound("Board not found.");
|
||||
|
||||
var endpoint = _videoStreamService.GetVideoEndpoint(boardId.ToString());
|
||||
return Ok(endpoint);
|
||||
}
|
||||
|
||||
// 禁用指定板子的 HDMI 传输
|
||||
[HttpPost("DisableHdmiTransmission")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> DisableHdmiTransmission()
|
||||
{
|
||||
var userName = User.FindFirstValue(ClaimTypes.Name);
|
||||
if (string.IsNullOrEmpty(userName))
|
||||
return Unauthorized("User name not found in claims.");
|
||||
|
||||
var db = new AppDataConnection();
|
||||
if (db == null)
|
||||
return NotFound("Database connection failed.");
|
||||
|
||||
var userRet = db.GetUserByName(userName);
|
||||
if (!userRet.IsSuccessful || !userRet.Value.HasValue)
|
||||
return NotFound("User not found.");
|
||||
|
||||
var user = userRet.Value.Value;
|
||||
var boardId = user.BoardID;
|
||||
if (boardId == Guid.Empty)
|
||||
return NotFound("No board bound to this user.");
|
||||
|
||||
try
|
||||
{
|
||||
await _videoStreamService.DisableHdmiTransmissionAsync(boardId.ToString());
|
||||
return Ok($"HDMI transmission for board {boardId} disabled.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, $"Failed to disable HDMI transmission for board {boardId}");
|
||||
return StatusCode(500, $"Error disabling HDMI transmission: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Database;
|
||||
using server.Services;
|
||||
|
||||
namespace server.Controllers;
|
||||
|
||||
@@ -15,6 +16,15 @@ public class JtagController : ControllerBase
|
||||
{
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly ProgressTrackerService _tracker;
|
||||
|
||||
private const string BITSTREAM_PATH = "bitstream/Jtag";
|
||||
|
||||
public JtagController(ProgressTrackerService tracker)
|
||||
{
|
||||
_tracker = tracker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 控制器首页信息
|
||||
/// </summary>
|
||||
@@ -117,14 +127,14 @@ public class JtagController : ControllerBase
|
||||
/// <param name="address">JTAG 设备地址</param>
|
||||
/// <param name="port">JTAG 设备端口</param>
|
||||
/// <param name="bitstreamId">比特流ID</param>
|
||||
/// <returns>下载结果</returns>
|
||||
/// <returns>进度跟踪TaskID</returns>
|
||||
[HttpPost("DownloadBitstream")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
public async ValueTask<IResult> DownloadBitstream(string address, int port, int bitstreamId)
|
||||
public async ValueTask<IResult> DownloadBitstream(string address, int port, int bitstreamId, CancellationToken cancelToken)
|
||||
{
|
||||
logger.Info($"User {User.Identity?.Name} initiating bitstream download to device {address}:{port} using bitstream ID: {bitstreamId}");
|
||||
|
||||
@@ -176,55 +186,67 @@ public class JtagController : ControllerBase
|
||||
|
||||
logger.Info($"User {username} processing bitstream file of size: {fileBytes.Length} bytes");
|
||||
|
||||
// 定义缓冲区大小: 32KB
|
||||
byte[] buffer = new byte[32 * 1024];
|
||||
byte[] revBuffer = new byte[32 * 1024];
|
||||
long totalBytesProcessed = 0;
|
||||
// 定义进度跟踪
|
||||
var (taskId, progress) = _tracker.CreateTask(cancelToken);
|
||||
progress.Report(10);
|
||||
|
||||
// 使用内存流处理文件
|
||||
using (var inputStream = new MemoryStream(fileBytes))
|
||||
using (var outputStream = new MemoryStream())
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
int bytesRead;
|
||||
while ((bytesRead = await inputStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
// 反转 32bits
|
||||
var retBuffer = Common.Number.ReverseBytes(buffer, 4);
|
||||
if (!retBuffer.IsSuccessful)
|
||||
{
|
||||
logger.Error($"User {username} failed to reverse bytes: {retBuffer.Error}");
|
||||
return TypedResults.InternalServerError(retBuffer.Error);
|
||||
}
|
||||
revBuffer = retBuffer.Value;
|
||||
// 定义缓冲区大小: 32KB
|
||||
byte[] buffer = new byte[32 * 1024];
|
||||
byte[] revBuffer = new byte[32 * 1024];
|
||||
long totalBytesProcessed = 0;
|
||||
|
||||
for (int i = 0; i < revBuffer.Length; i++)
|
||||
// 使用内存流处理文件
|
||||
using (var inputStream = new MemoryStream(fileBytes))
|
||||
using (var outputStream = new MemoryStream())
|
||||
{
|
||||
int bytesRead;
|
||||
while ((bytesRead = await inputStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
revBuffer[i] = Common.Number.ReverseBits(revBuffer[i]);
|
||||
// 反转 32bits
|
||||
var retBuffer = Common.Number.ReverseBytes(buffer, 4);
|
||||
if (!retBuffer.IsSuccessful)
|
||||
{
|
||||
logger.Error($"User {username} failed to reverse bytes: {retBuffer.Error}");
|
||||
progress.Error($"User {username} failed to reverse bytes: {retBuffer.Error}");
|
||||
return;
|
||||
}
|
||||
revBuffer = retBuffer.Value;
|
||||
|
||||
for (int i = 0; i < revBuffer.Length; i++)
|
||||
{
|
||||
revBuffer[i] = Common.Number.ReverseBits(revBuffer[i]);
|
||||
}
|
||||
|
||||
await outputStream.WriteAsync(revBuffer, 0, bytesRead);
|
||||
totalBytesProcessed += bytesRead;
|
||||
}
|
||||
|
||||
await outputStream.WriteAsync(revBuffer, 0, bytesRead);
|
||||
totalBytesProcessed += bytesRead;
|
||||
}
|
||||
// 获取处理后的数据
|
||||
var processedBytes = outputStream.ToArray();
|
||||
logger.Info($"User {username} processed {totalBytesProcessed} bytes for device {address}");
|
||||
|
||||
// 获取处理后的数据
|
||||
var processedBytes = outputStream.ToArray();
|
||||
logger.Info($"User {username} processed {totalBytesProcessed} bytes for device {address}");
|
||||
progress.Report(20);
|
||||
|
||||
// 下载比特流
|
||||
var jtagCtrl = new Peripherals.JtagClient.Jtag(address, port);
|
||||
var ret = await jtagCtrl.DownloadBitstream(processedBytes);
|
||||
// 下载比特流
|
||||
var jtagCtrl = new Peripherals.JtagClient.Jtag(address, port);
|
||||
var ret = await jtagCtrl.DownloadBitstream(processedBytes);
|
||||
|
||||
if (ret.IsSuccessful)
|
||||
{
|
||||
logger.Info($"User {username} successfully downloaded bitstream '{bitstream.ResourceName}' to device {address}");
|
||||
return TypedResults.Ok(ret.Value);
|
||||
if (ret.IsSuccessful)
|
||||
{
|
||||
logger.Info($"User {username} successfully downloaded bitstream '{bitstream.ResourceName}' to device {address}");
|
||||
progress.Finish();
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error($"User {username} failed to download bitstream to device {address}: {ret.Error}");
|
||||
progress.Error($"User {username} failed to download bitstream to device {address}: {ret.Error}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error($"User {username} failed to download bitstream to device {address}: {ret.Error}");
|
||||
return TypedResults.InternalServerError(ret.Error);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return TypedResults.Ok(taskId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -58,6 +58,10 @@ public class LogicAnalyzerController : ControllerBase
|
||||
/// </summary>
|
||||
public AnalyzerChannelDiv ChannelDiv { get; set; } = AnalyzerChannelDiv.EIGHT;
|
||||
/// <summary>
|
||||
/// 时钟分频系数
|
||||
/// </summary>
|
||||
public AnalyzerClockDiv ClockDiv { get; set; } = AnalyzerClockDiv.DIV1;
|
||||
/// <summary>
|
||||
/// 信号触发配置列表
|
||||
/// </summary>
|
||||
public SignalTriggerConfig[] SignalConfigs { get; set; } = Array.Empty<SignalTriggerConfig>();
|
||||
@@ -248,6 +252,7 @@ public class LogicAnalyzerController : ControllerBase
|
||||
/// <param name="capture_length">深度</param>
|
||||
/// <param name="pre_capture_length">预采样深度</param>
|
||||
/// <param name="channel_div">有效通道(0-[1],1-[2],2-[4],3-[8],4-[16],5-[32])</param>
|
||||
/// <param name="clock_div">采样时钟分频系数</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("SetCaptureParams")]
|
||||
[EnableCors("Users")]
|
||||
@@ -255,11 +260,12 @@ public class LogicAnalyzerController : ControllerBase
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
public async Task<IActionResult> SetCaptureParams(int capture_length, int pre_capture_length, AnalyzerChannelDiv channel_div)
|
||||
public async Task<IActionResult> SetCaptureParams(int capture_length, int pre_capture_length, AnalyzerChannelDiv channel_div, AnalyzerClockDiv clock_div)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (capture_length < 0 || capture_length > 2048*32)
|
||||
//DDR深度为 32'h01000000 - 32'h0FFFFFFF
|
||||
if (capture_length < 0 || capture_length > 0x10000000 - 0x01000000)
|
||||
return BadRequest("采样深度设置错误");
|
||||
if (pre_capture_length < 0 || pre_capture_length >= capture_length)
|
||||
return BadRequest("预采样深度必须小于捕获深度");
|
||||
@@ -268,18 +274,18 @@ public class LogicAnalyzerController : ControllerBase
|
||||
if (analyzer == null)
|
||||
return BadRequest("用户未绑定有效的实验板");
|
||||
|
||||
var result = await analyzer.SetCaptureParams(capture_length, pre_capture_length, channel_div);
|
||||
var result = await analyzer.SetCaptureParams(capture_length, pre_capture_length, channel_div, clock_div);
|
||||
if (!result.IsSuccessful)
|
||||
{
|
||||
logger.Error($"设置深度、预采样深度、有效通道失败: {result.Error}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "设置深度、预采样深度、有效通道失败");
|
||||
logger.Error($"设置深度、预采样深度、有效通道、时钟分频失败: {result.Error}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "设置深度、预采样深度、有效通道、时钟分频失败");
|
||||
}
|
||||
|
||||
return Ok(result.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "设置深度、预采样深度、有效通道失败时发生异常");
|
||||
logger.Error(ex, "设置深度、预采样深度、有效通道、时钟分频失败时发生异常");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "操作失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
@@ -331,7 +337,7 @@ public class LogicAnalyzerController : ControllerBase
|
||||
}
|
||||
// 设置深度、预采样深度、有效通道
|
||||
var paramsResult = await analyzer.SetCaptureParams(
|
||||
config.CaptureLength, config.PreCaptureLength, config.ChannelDiv);
|
||||
config.CaptureLength, config.PreCaptureLength, config.ChannelDiv, config.ClockDiv);
|
||||
if (!paramsResult.IsSuccessful)
|
||||
{
|
||||
logger.Error($"设置深度、预采样深度、有效通道失败: {paramsResult.Error}");
|
||||
|
||||
@@ -1,77 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Security.Claims;
|
||||
using Database;
|
||||
using DotNext;
|
||||
|
||||
/// <summary>
|
||||
/// 视频流控制器,支持动态配置摄像头连接
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
public class VideoStreamController : ControllerBase
|
||||
{
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
private readonly server.Services.HttpVideoStreamService _videoStreamService;
|
||||
|
||||
/// <summary>
|
||||
/// 视频流信息结构体
|
||||
/// </summary>
|
||||
public class StreamInfoResult
|
||||
{
|
||||
/// <summary>
|
||||
/// TODO:
|
||||
/// </summary>
|
||||
public int FrameRate { get; set; }
|
||||
/// <summary>
|
||||
/// TODO:
|
||||
/// </summary>
|
||||
public int FrameWidth { get; set; }
|
||||
/// <summary>
|
||||
/// TODO:
|
||||
/// </summary>
|
||||
public int FrameHeight { get; set; }
|
||||
/// <summary>
|
||||
/// TODO:
|
||||
/// </summary>
|
||||
public string Format { get; set; } = "MJPEG";
|
||||
/// <summary>
|
||||
/// TODO:
|
||||
/// </summary>
|
||||
public string HtmlUrl { get; set; } = "";
|
||||
/// <summary>
|
||||
/// TODO:
|
||||
/// </summary>
|
||||
public string MjpegUrl { get; set; } = "";
|
||||
/// <summary>
|
||||
/// TODO:
|
||||
/// </summary>
|
||||
public string SnapshotUrl { get; set; } = "";
|
||||
/// <summary>
|
||||
/// TODO:
|
||||
/// </summary>
|
||||
public string UsbCameraUrl { get; set; } = "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 摄像头配置请求模型
|
||||
/// </summary>
|
||||
public class CameraConfigRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 摄像头地址
|
||||
/// </summary>
|
||||
[Required]
|
||||
[RegularExpression(@"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", ErrorMessage = "请输入有效的IP地址")]
|
||||
public string Address { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 摄像头端口
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Range(1, 65535, ErrorMessage = "端口必须在1-65535范围内")]
|
||||
public int Port { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分辨率配置请求模型
|
||||
/// </summary>
|
||||
@@ -92,6 +37,14 @@ public class VideoStreamController : ControllerBase
|
||||
public int Height { get; set; }
|
||||
}
|
||||
|
||||
public class AvailableResolutionsResponse
|
||||
{
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Value => $"{Width}x{Height}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化HTTP视频流控制器
|
||||
/// </summary>
|
||||
@@ -102,6 +55,40 @@ public class VideoStreamController : ControllerBase
|
||||
_videoStreamService = videoStreamService;
|
||||
}
|
||||
|
||||
private Optional<string> TryGetBoardId()
|
||||
{
|
||||
var userName = User.FindFirstValue(ClaimTypes.Name);
|
||||
if (string.IsNullOrEmpty(userName))
|
||||
{
|
||||
logger.Error("User name not found in claims.");
|
||||
return Optional<string>.None;
|
||||
}
|
||||
|
||||
var db = new AppDataConnection();
|
||||
if (db == null)
|
||||
{
|
||||
logger.Error("Database connection failed.");
|
||||
return Optional<string>.None;
|
||||
}
|
||||
|
||||
var userRet = db.GetUserByName(userName);
|
||||
if (!userRet.IsSuccessful || !userRet.Value.HasValue)
|
||||
{
|
||||
logger.Error("User not found.");
|
||||
return Optional<string>.None;
|
||||
}
|
||||
|
||||
var user = userRet.Value.Value;
|
||||
var boardId = user.BoardID;
|
||||
if (boardId == Guid.Empty)
|
||||
{
|
||||
logger.Error("No board bound to this user.");
|
||||
return Optional<string>.None;
|
||||
}
|
||||
|
||||
return boardId.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 HTTP 视频流服务状态
|
||||
/// </summary>
|
||||
@@ -114,8 +101,6 @@ public class VideoStreamController : ControllerBase
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("GetStatus方法被调用,控制器:{Controller},路径:api/VideoStream/Status", this.GetType().Name);
|
||||
|
||||
// 使用HttpVideoStreamService提供的状态信息
|
||||
var status = _videoStreamService.GetServiceStatus();
|
||||
|
||||
@@ -129,101 +114,18 @@ public class VideoStreamController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 HTTP 视频流信息
|
||||
/// </summary>
|
||||
/// <returns>流信息</returns>
|
||||
[HttpGet("StreamInfo")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(StreamInfoResult), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||
public IResult GetStreamInfo()
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("获取 HTTP 视频流信息");
|
||||
var result = new StreamInfoResult
|
||||
{
|
||||
FrameRate = _videoStreamService.FrameRate,
|
||||
FrameWidth = _videoStreamService.FrameWidth,
|
||||
FrameHeight = _videoStreamService.FrameHeight,
|
||||
Format = "MJPEG",
|
||||
HtmlUrl = $"http://{Global.localhost}:{_videoStreamService.ServerPort}/video-feed.html",
|
||||
MjpegUrl = $"http://{Global.localhost}:{_videoStreamService.ServerPort}/video-stream",
|
||||
SnapshotUrl = $"http://{Global.localhost}:{_videoStreamService.ServerPort}/snapshot",
|
||||
UsbCameraUrl = $"http://{Global.localhost}:{_videoStreamService.ServerPort}/usb-camera"
|
||||
};
|
||||
return TypedResults.Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "获取 HTTP 视频流信息失败");
|
||||
return TypedResults.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置摄像头连接参数
|
||||
/// </summary>
|
||||
/// <param name="config">摄像头配置</param>
|
||||
/// <returns>配置结果</returns>
|
||||
[HttpPost("ConfigureCamera")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(object), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IResult> ConfigureCamera([FromBody] CameraConfigRequest config)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("配置摄像头连接: {Address}:{Port}", config.Address, config.Port);
|
||||
|
||||
var success = await _videoStreamService.ConfigureCameraAsync(config.Address, config.Port);
|
||||
|
||||
if (success)
|
||||
{
|
||||
return TypedResults.Ok(new
|
||||
{
|
||||
success = true,
|
||||
message = "摄像头配置成功",
|
||||
cameraAddress = config.Address,
|
||||
cameraPort = config.Port
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
return TypedResults.BadRequest(new
|
||||
{
|
||||
success = false,
|
||||
message = "摄像头配置失败",
|
||||
cameraAddress = config.Address,
|
||||
cameraPort = config.Port
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "配置摄像头连接失败");
|
||||
return TypedResults.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前摄像头配置
|
||||
/// </summary>
|
||||
/// <returns>摄像头配置信息</returns>
|
||||
[HttpGet("CameraConfig")]
|
||||
[HttpGet("MyEndpoint")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||
public IResult GetCameraConfig()
|
||||
public IResult MyEndpoint()
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("获取摄像头配置");
|
||||
var cameraStatus = _videoStreamService.GetCameraStatus();
|
||||
var boardId = TryGetBoardId().OrThrow(() => new Exception("Board ID not found"));
|
||||
var endpoint = _videoStreamService.GetVideoEndpoint(boardId);
|
||||
|
||||
return TypedResults.Ok(cameraStatus);
|
||||
return TypedResults.Ok(endpoint);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -232,22 +134,6 @@ public class VideoStreamController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 控制 HTTP 视频流服务开关
|
||||
/// </summary>
|
||||
/// <param name="enabled">是否启用服务</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("SetEnabled")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IResult> SetEnabled([FromQuery] bool enabled)
|
||||
{
|
||||
logger.Info("设置视频流服务开关: {Enabled}", enabled);
|
||||
await _videoStreamService.SetEnable(enabled);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试 HTTP 视频流连接
|
||||
/// </summary>
|
||||
@@ -260,32 +146,23 @@ public class VideoStreamController : ControllerBase
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("测试 HTTP 视频流连接");
|
||||
var boardId = TryGetBoardId().OrThrow(() => new Exception("Board ID not found"));
|
||||
var endpoint = _videoStreamService.GetVideoEndpoint(boardId);
|
||||
|
||||
// 尝试通过HTTP请求检查视频流服务是否可访问
|
||||
bool isConnected = false;
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.Timeout = TimeSpan.FromSeconds(2); // 设置较短的超时时间
|
||||
var response = await httpClient.GetAsync($"http://{Global.localhost}:{_videoStreamService.ServerPort}/");
|
||||
var response = await httpClient.GetAsync(endpoint.MjpegUrl);
|
||||
|
||||
// 只要能连接上就认为成功,不管返回状态
|
||||
isConnected = response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
logger.Info("测试摄像头连接");
|
||||
var ret = await _videoStreamService.TestCameraConnection(boardId);
|
||||
|
||||
var (isSuccess, message) = await _videoStreamService.TestCameraConnectionAsync();
|
||||
|
||||
return TypedResults.Ok(new
|
||||
{
|
||||
isConnected = isConnected,
|
||||
success = isSuccess,
|
||||
message = message,
|
||||
cameraAddress = _videoStreamService.CameraAddress,
|
||||
cameraPort = _videoStreamService.CameraPort,
|
||||
timestamp = DateTime.Now
|
||||
});
|
||||
return TypedResults.Ok(ret);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -295,6 +172,23 @@ public class VideoStreamController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("DisableTransmission")]
|
||||
public async Task<IActionResult> DisableHdmiTransmission()
|
||||
{
|
||||
try
|
||||
{
|
||||
var boardId = TryGetBoardId().OrThrow(() => new ArgumentException("Board ID is required"));
|
||||
|
||||
await _videoStreamService.DisableHdmiTransmissionAsync(boardId.ToString());
|
||||
return Ok($"HDMI transmission for board {boardId} disabled.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, $"Failed to disable HDMI transmission for board");
|
||||
return StatusCode(500, $"Error disabling HDMI transmission: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置视频流分辨率
|
||||
/// </summary>
|
||||
@@ -309,16 +203,16 @@ public class VideoStreamController : ControllerBase
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info($"设置视频流分辨率为 {request.Width}x{request.Height}");
|
||||
var boardId = TryGetBoardId().OrThrow(() => new Exception("Board ID not found"));
|
||||
|
||||
var (isSuccess, message) = await _videoStreamService.SetResolutionAsync(request.Width, request.Height);
|
||||
var ret = await _videoStreamService.SetResolutionAsync(boardId, request.Width, request.Height);
|
||||
|
||||
if (isSuccess)
|
||||
if (ret.IsSuccessful && ret.Value)
|
||||
{
|
||||
return TypedResults.Ok(new
|
||||
{
|
||||
success = true,
|
||||
message = message,
|
||||
message = $"成功设置分辨率为 {request.Width}x{request.Height}",
|
||||
width = request.Width,
|
||||
height = request.Height,
|
||||
timestamp = DateTime.Now
|
||||
@@ -329,7 +223,7 @@ public class VideoStreamController : ControllerBase
|
||||
return TypedResults.BadRequest(new
|
||||
{
|
||||
success = false,
|
||||
message = message,
|
||||
message = ret.Error?.ToString() ?? "未知错误",
|
||||
timestamp = DateTime.Now
|
||||
});
|
||||
}
|
||||
@@ -341,37 +235,6 @@ public class VideoStreamController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前分辨率
|
||||
/// </summary>
|
||||
/// <returns>当前分辨率信息</returns>
|
||||
[HttpGet("Resolution")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
|
||||
public IResult GetCurrentResolution()
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("获取当前视频流分辨率");
|
||||
|
||||
var (width, height) = _videoStreamService.GetCurrentResolution();
|
||||
|
||||
return TypedResults.Ok(new
|
||||
{
|
||||
width = width,
|
||||
height = height,
|
||||
resolution = $"{width}x{height}",
|
||||
timestamp = DateTime.Now
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "获取当前分辨率失败");
|
||||
return TypedResults.InternalServerError($"获取当前分辨率失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取支持的分辨率列表
|
||||
/// </summary>
|
||||
@@ -382,29 +245,19 @@ public class VideoStreamController : ControllerBase
|
||||
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
|
||||
public IResult GetSupportedResolutions()
|
||||
{
|
||||
try
|
||||
// (640, 480, "640x480 (VGA)"),
|
||||
// (960, 540, "960x540 (qHD)"),
|
||||
// (1280, 720, "1280x720 (HD)"),
|
||||
// (1280, 960, "1280x960 (SXGA)"),
|
||||
// (1920, 1080, "1920x1080 (Full HD)")
|
||||
return TypedResults.Ok(new AvailableResolutionsResponse[]
|
||||
{
|
||||
logger.Info("获取支持的分辨率列表");
|
||||
|
||||
var resolutions = _videoStreamService.GetSupportedResolutions();
|
||||
|
||||
return TypedResults.Ok(new
|
||||
{
|
||||
resolutions = resolutions.Select(r => new
|
||||
{
|
||||
width = r.Width,
|
||||
height = r.Height,
|
||||
name = r.Name,
|
||||
value = $"{r.Width}x{r.Height}"
|
||||
}),
|
||||
timestamp = DateTime.Now
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "获取支持的分辨率列表失败");
|
||||
return TypedResults.InternalServerError($"获取支持的分辨率列表失败: {ex.Message}");
|
||||
}
|
||||
new AvailableResolutionsResponse { Width = 640, Height = 480, Name = "640x480(VGA)" },
|
||||
new AvailableResolutionsResponse { Width = 960, Height = 480, Name = "960x480(qHD)" },
|
||||
new AvailableResolutionsResponse { Width = 1280, Height = 720, Name = "1280x720(HD)" },
|
||||
new AvailableResolutionsResponse { Width = 1280, Height = 960, Name = "1280x960(SXGA)" },
|
||||
new AvailableResolutionsResponse { Width = 1920, Height = 1080, Name = "1920x1080(Full HD)" }
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -420,9 +273,9 @@ public class VideoStreamController : ControllerBase
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("收到初始化自动对焦请求");
|
||||
var boardId = TryGetBoardId().OrThrow(() => new Exception("Board ID not found"));
|
||||
|
||||
var result = await _videoStreamService.InitAutoFocusAsync();
|
||||
var result = await _videoStreamService.InitAutoFocusAsync(boardId);
|
||||
|
||||
if (result)
|
||||
{
|
||||
@@ -465,9 +318,9 @@ public class VideoStreamController : ControllerBase
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("收到执行自动对焦请求");
|
||||
var boardId = TryGetBoardId().OrThrow(() => new Exception("Board ID not found"));
|
||||
|
||||
var result = await _videoStreamService.PerformAutoFocusAsync();
|
||||
var result = await _videoStreamService.PerformAutoFocusAsync(boardId);
|
||||
|
||||
if (result)
|
||||
{
|
||||
@@ -496,61 +349,4 @@ public class VideoStreamController : ControllerBase
|
||||
return TypedResults.InternalServerError($"执行自动对焦失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行一次自动对焦 (GET方式)
|
||||
/// </summary>
|
||||
/// <returns>对焦结果</returns>
|
||||
[HttpGet("Focus")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(object), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IResult> Focus()
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("收到执行一次对焦请求 (GET)");
|
||||
|
||||
// 检查摄像头是否已配置
|
||||
if (!_videoStreamService.IsCameraConfigured())
|
||||
{
|
||||
logger.Warn("摄像头未配置,无法执行对焦");
|
||||
return TypedResults.BadRequest(new
|
||||
{
|
||||
success = false,
|
||||
message = "摄像头未配置,请先配置摄像头连接",
|
||||
timestamp = DateTime.Now
|
||||
});
|
||||
}
|
||||
|
||||
var result = await _videoStreamService.PerformAutoFocusAsync();
|
||||
|
||||
if (result)
|
||||
{
|
||||
logger.Info("对焦执行成功");
|
||||
return TypedResults.Ok(new
|
||||
{
|
||||
success = true,
|
||||
message = "对焦执行成功",
|
||||
timestamp = DateTime.Now
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Warn("对焦执行失败");
|
||||
return TypedResults.BadRequest(new
|
||||
{
|
||||
success = false,
|
||||
message = "对焦执行失败",
|
||||
timestamp = DateTime.Now
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "执行对焦时发生异常");
|
||||
return TypedResults.InternalServerError($"执行对焦失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using DotNext;
|
||||
@@ -8,7 +7,7 @@ using System.Collections.Concurrent;
|
||||
using TypedSignalR.Client;
|
||||
using Tapper;
|
||||
|
||||
namespace server.Hubs.JtagHub;
|
||||
namespace server.Hubs;
|
||||
|
||||
[Hub]
|
||||
public interface IJtagHub
|
||||
|
||||
61
server/src/Hubs/ProgressHub.cs
Normal file
61
server/src/Hubs/ProgressHub.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using TypedSignalR.Client;
|
||||
using Tapper;
|
||||
using server.Services;
|
||||
|
||||
namespace server.Hubs;
|
||||
|
||||
[Hub]
|
||||
public interface IProgressHub
|
||||
{
|
||||
Task<bool> Join(string taskId);
|
||||
}
|
||||
|
||||
[Receiver]
|
||||
public interface IProgressReceiver
|
||||
{
|
||||
Task OnReceiveProgress(ProgressInfo message);
|
||||
}
|
||||
|
||||
[TranspilationSource]
|
||||
public enum ProgressStatus
|
||||
{
|
||||
Pending,
|
||||
InProgress,
|
||||
Completed,
|
||||
Canceled,
|
||||
Failed
|
||||
}
|
||||
|
||||
[TranspilationSource]
|
||||
public class ProgressInfo
|
||||
{
|
||||
public string TaskId { get; }
|
||||
public ProgressStatus Status { get; }
|
||||
public int ProgressPercent { get; }
|
||||
public string ErrorMessage { get; }
|
||||
};
|
||||
|
||||
[Authorize]
|
||||
[EnableCors("SignalR")]
|
||||
public class ProgressHub : Hub<IProgressReceiver>, IProgressHub
|
||||
{
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly IHubContext<ProgressHub, IProgressReceiver> _hubContext;
|
||||
private readonly ProgressTrackerService _tracker;
|
||||
|
||||
public ProgressHub(IHubContext<ProgressHub, IProgressReceiver> hubContext, ProgressTrackerService tracker)
|
||||
{
|
||||
_hubContext = hubContext;
|
||||
_tracker = tracker;
|
||||
}
|
||||
|
||||
public async Task<bool> Join(string taskId)
|
||||
{
|
||||
return _tracker.BindTask(taskId, Context.ConnectionId);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Net;
|
||||
using DotNext;
|
||||
using Peripherals.PowerClient;
|
||||
using WebProtocol;
|
||||
|
||||
namespace Peripherals.CameraClient;
|
||||
@@ -16,7 +15,7 @@ static class CameraAddr
|
||||
public const UInt32 CAMERA_POWER = BASE + 0x10; //[0]: rstn, 0 is reset. [8]: power down, 1 is down.
|
||||
}
|
||||
|
||||
class Camera
|
||||
public class Camera
|
||||
{
|
||||
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
@@ -276,7 +275,7 @@ class Camera
|
||||
{
|
||||
var currentAddress = (UInt16)(baseAddress + i - 1);
|
||||
var data = (byte)cmd[i];
|
||||
|
||||
|
||||
logger.Debug($"ConfigureRegisters: 写入地址=0x{currentAddress:X4}, 数据=0x{data:X2}");
|
||||
|
||||
// 准备I2C数据:16位地址 + 8位数据
|
||||
@@ -322,14 +321,14 @@ class Camera
|
||||
public async ValueTask<Result<byte>> ReadRegister(UInt16 register)
|
||||
{
|
||||
var i2c = new Peripherals.I2cClient.I2c(this.address, this.port, this.taskID, this.timeout);
|
||||
|
||||
|
||||
// Convert 16-bit register address to byte array
|
||||
var registerBytes = new byte[] { (byte)(register >> 8), (byte)(register & 0xFF) };
|
||||
|
||||
|
||||
var ret = await i2c.ReadData(CAM_I2C_ADDR, registerBytes, 1, CAM_PROTO);
|
||||
if (!ret.IsSuccessful)
|
||||
return new(ret.Error);
|
||||
|
||||
|
||||
return new Result<byte>(ret.Value[0]);
|
||||
}
|
||||
|
||||
@@ -412,25 +411,25 @@ class Camera
|
||||
[0x3801, unchecked((byte)(hStart & 0xFF))],
|
||||
[0x3802, unchecked((byte)((vStart >> 8) & 0xFF))],
|
||||
[0x3803, unchecked((byte)(vStart & 0xFF))],
|
||||
|
||||
|
||||
// H_END/V_END
|
||||
[0x3804, unchecked((byte)((hEnd >> 8) & 0xFF))],
|
||||
[0x3805, unchecked((byte)(hEnd & 0xFF))],
|
||||
[0x3806, unchecked((byte)((vEnd >> 8) & 0xFF))],
|
||||
[0x3807, unchecked((byte)(vEnd & 0xFF))],
|
||||
|
||||
|
||||
// 输出像素个数
|
||||
[0x3808, unchecked((byte)((dvpHo >> 8) & 0xFF))],
|
||||
[0x3809, unchecked((byte)(dvpHo & 0xFF))],
|
||||
[0x380A, unchecked((byte)((dvpVo >> 8) & 0xFF))],
|
||||
[0x380B, unchecked((byte)(dvpVo & 0xFF))],
|
||||
|
||||
|
||||
// 总像素
|
||||
[0x380C, unchecked((byte)((hts >> 8) & 0xFF))],
|
||||
[0x380D, unchecked((byte)(hts & 0xFF))],
|
||||
[0x380E, unchecked((byte)((vts >> 8) & 0xFF))],
|
||||
[0x380F, unchecked((byte)(vts & 0xFF))],
|
||||
|
||||
|
||||
// H_OFFSET/V_OFFSET
|
||||
[0x3810, unchecked((byte)((hOffset >> 8) & 0xFF))],
|
||||
[0x3811, unchecked((byte)(hOffset & 0xFF))],
|
||||
@@ -521,7 +520,7 @@ class Camera
|
||||
hOffset: 16, vOffset: 4,
|
||||
hWindow: 2624, vWindow: 1456
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -537,7 +536,7 @@ class Camera
|
||||
hOffset: 16, vOffset: 4,
|
||||
hWindow: 2624, vWindow: 1456
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -637,7 +636,7 @@ class Camera
|
||||
[0x3008, 0x42] // 休眠命令
|
||||
};
|
||||
|
||||
return await ConfigureRegisters(sleepRegisters, customDelayMs: 50);
|
||||
return await ConfigureRegisters(sleepRegisters, customDelayMs: 50);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1305,7 +1304,7 @@ class Camera
|
||||
UInt16 firmwareAddr = 0x8000;
|
||||
var firmwareCommand = new UInt16[1 + OV5640_AF_FIRMWARE.Length];
|
||||
firmwareCommand[0] = firmwareAddr;
|
||||
|
||||
|
||||
// 将固件数据复制到命令数组中
|
||||
for (int i = 0; i < OV5640_AF_FIRMWARE.Length; i++)
|
||||
{
|
||||
@@ -1425,7 +1424,7 @@ class Camera
|
||||
logger.Error($"自动对焦超时,状态: 0x{readResult.Value:X2}");
|
||||
return new(new Exception($"自动对焦超时,状态: 0x{readResult.Value:X2}"));
|
||||
}
|
||||
|
||||
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,28 +55,28 @@ class DebuggerCmd
|
||||
public const UInt32 ClearSignal = 0xFFFF_FFFF;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 信号捕获模式枚举
|
||||
/// </summary>
|
||||
public enum CaptureMode : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 无捕获模式
|
||||
/// </summary>
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 低电平触发模式
|
||||
/// </summary>
|
||||
Logic0 = 1,
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 高电平触发模式
|
||||
/// </summary>
|
||||
Logic1 = 2,
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 上升沿触发模式
|
||||
/// </summary>
|
||||
Rise = 3,
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 下降沿触发模式
|
||||
/// </summary>
|
||||
Fall = 4,
|
||||
@@ -170,7 +170,7 @@ public class DebuggerClient
|
||||
/// <returns>操作结果,成功返回状态标志字节,失败返回错误信息</returns>
|
||||
public async ValueTask<Result<byte>> ReadFlag()
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, this.taskID, DebuggerAddr.Signal, this.timeout);
|
||||
var ret = await UDPClientPool.ReadAddrByte(this.ep, this.taskID, DebuggerAddr.Signal, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to read flag: {ret.Error}");
|
||||
|
||||
@@ -32,14 +32,16 @@ class HdmiIn
|
||||
/// </summary>
|
||||
/// <param name="address">HDMI输入设备IP地址</param>
|
||||
/// <param name="port">HDMI输入设备端口</param>
|
||||
/// <param name="taskID">任务ID</param>
|
||||
/// <param name="timeout">超时时间(毫秒)</param>
|
||||
public HdmiIn(string address, int port, int timeout = 500)
|
||||
public HdmiIn(string address, int port, int taskID, int timeout = 500)
|
||||
{
|
||||
if (timeout < 0)
|
||||
throw new ArgumentException("Timeout couldn't be negative", nameof(timeout));
|
||||
this.address = address;
|
||||
this.port = port;
|
||||
this.ep = new IPEndPoint(IPAddress.Parse(address), port);
|
||||
this.taskID = taskID;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@@ -98,6 +100,51 @@ class HdmiIn
|
||||
return result.Value;
|
||||
}
|
||||
|
||||
public async ValueTask<(byte[] header, byte[] data, byte[] footer)?> GetMJpegFrame()
|
||||
{
|
||||
// 从HDMI读取RGB24数据
|
||||
var readStartTime = DateTime.UtcNow;
|
||||
var frameResult = await ReadFrame();
|
||||
var readEndTime = DateTime.UtcNow;
|
||||
var readTime = (readEndTime - readStartTime).TotalMilliseconds;
|
||||
|
||||
if (!frameResult.IsSuccessful || frameResult.Value == null)
|
||||
{
|
||||
logger.Warn("HDMI帧读取失败或为空");
|
||||
return null;
|
||||
}
|
||||
|
||||
var rgb24Data = frameResult.Value;
|
||||
|
||||
// 验证数据长度是否正确 (RGB24为每像素2字节)
|
||||
var expectedLength = _currentWidth * _currentHeight * 2;
|
||||
if (rgb24Data.Length != expectedLength)
|
||||
{
|
||||
logger.Warn("HDMI数据长度不匹配,期望: {Expected}, 实际: {Actual}",
|
||||
expectedLength, rgb24Data.Length);
|
||||
}
|
||||
|
||||
// 将RGB24转换为JPEG(参考Camera版本的处理)
|
||||
var jpegStartTime = DateTime.UtcNow;
|
||||
var jpegResult = Common.Image.ConvertRGB24ToJpeg(rgb24Data, _currentWidth, _currentHeight, 80);
|
||||
var jpegEndTime = DateTime.UtcNow;
|
||||
var jpegTime = (jpegEndTime - jpegStartTime).TotalMilliseconds;
|
||||
|
||||
if (!jpegResult.IsSuccessful)
|
||||
{
|
||||
logger.Error("HDMI RGB24转JPEG失败: {Error}", jpegResult.Error);
|
||||
return null;
|
||||
}
|
||||
|
||||
var jpegData = jpegResult.Value;
|
||||
|
||||
// 发送MJPEG帧(使用Camera版本的格式)
|
||||
var mjpegFrameHeader = Common.Image.CreateMjpegFrameHeader(jpegData.Length);
|
||||
var mjpegFrameFooter = Common.Image.CreateMjpegFrameFooter();
|
||||
|
||||
return (mjpegFrameHeader, jpegData, mjpegFrameFooter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前分辨率
|
||||
/// </summary>
|
||||
|
||||
@@ -8,8 +8,8 @@ static class I2cAddr
|
||||
|
||||
const UInt32 Base = 0x6000_0000;
|
||||
|
||||
/// <summary>
|
||||
/// 0x0000_0000:
|
||||
/// <summary>
|
||||
/// 0x0000_0000:
|
||||
/// [7:0] 本次传输的i2c地址(最高位总为0);
|
||||
/// [8] 1为读,0为写;
|
||||
/// [16] 1为SCCB协议,0为I2C协议;
|
||||
@@ -17,45 +17,45 @@ static class I2cAddr
|
||||
/// </summary>
|
||||
public const UInt32 BaseConfig = Base + 0x0000_0000;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0001:
|
||||
/// [15:0] 本次传输的数据量(以字节为单位,0为传1个字节);
|
||||
/// [31:16] 若本次传输为读的DUMMY数据量(字节为单位,0为传1个字节)
|
||||
/// </summary>
|
||||
public const UInt32 TranConfig = Base + 0x0000_0001;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0002: [0] cmd_done; [8] cmd_error;
|
||||
/// </summary>
|
||||
public const UInt32 Flag = Base + 0x0000_0002;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0003: FIFO写入口,仅低8位有效,只写
|
||||
/// </summary>
|
||||
public const UInt32 Write = Base + 0x0000_0003;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0004: FIFO读出口,仅低8位有效,只读
|
||||
/// </summary>
|
||||
public const UInt32 Read = Base + 0x0000_0004;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0005: [0] FIFO写入口清空;[8] FIFO读出口清空;
|
||||
/// </summary>
|
||||
public const UInt32 Clear = Base + 0x0000_0005;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// [TODO:Enum]
|
||||
/// </summary>
|
||||
public enum I2cProtocol
|
||||
{
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// [TODO:Enum]
|
||||
/// </summary>
|
||||
I2c = 0,
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// [TODO:Enum]
|
||||
/// </summary>
|
||||
SCCB = 1
|
||||
@@ -296,7 +296,7 @@ public class I2c
|
||||
|
||||
// 读取数据
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, this.taskID, I2cAddr.Read);
|
||||
var ret = await UDPClientPool.ReadAddrByte(this.ep, this.taskID, I2cAddr.Read);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to read data from I2C FIFO: {ret.Error}");
|
||||
|
||||
281
server/src/Peripherals/JpegClient.cs
Normal file
281
server/src/Peripherals/JpegClient.cs
Normal file
@@ -0,0 +1,281 @@
|
||||
using System.Net;
|
||||
using DotNext;
|
||||
using Common;
|
||||
|
||||
namespace Peripherals.JpegClient;
|
||||
|
||||
static class JpegAddr
|
||||
{
|
||||
const UInt32 BASE = 0x0000_0000;
|
||||
public const UInt32 ENABLE = BASE + 0x0;
|
||||
public const UInt32 FRAME_NUM = BASE + 0x1;
|
||||
public const UInt32 FRAME_INFO = BASE + 0x2;
|
||||
public const UInt32 FRAME_SAMPLE_RATE = BASE + 0x3;
|
||||
public const UInt32 FRAME_DATA_MAX_POINTER = BASE + 0x4;
|
||||
|
||||
public const UInt32 DDR_FRAME_DATA_ADDR = 0x0000_0000;
|
||||
public const UInt32 DDR_FRAME_DATA_MAX_ADDR = 0x8000_0000;
|
||||
}
|
||||
|
||||
public class JpegInfo
|
||||
{
|
||||
public UInt32 Width { get; set; }
|
||||
public UInt32 Height { get; set; }
|
||||
public UInt32 Size { get; set; }
|
||||
|
||||
public JpegInfo(UInt32 width, UInt32 height, UInt32 size)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
public JpegInfo(byte[] data)
|
||||
{
|
||||
if (data.Length < 8)
|
||||
throw new ArgumentException("Invalid data length", nameof(data));
|
||||
|
||||
Width = ((UInt32)(data[5] << 8 + data[6] & 0xF0));
|
||||
Height = ((UInt32)((data[6] & 0x0F) << 4 + data[7]));
|
||||
Size = Number.BytesToUInt32(data, 0, 4).Value;
|
||||
}
|
||||
}
|
||||
|
||||
public enum JpegSampleRate : UInt32
|
||||
{
|
||||
RATE_1_1 = 0b1111_1111_1111_1111_1111_1111_1111_1111,
|
||||
RATE_1_2 = 0b1010_1010_1010_1010_1010_1010_1010_1010,
|
||||
RATE_1_4 = 0b1000_1000_1000_1000_1000_1000_1000_1000,
|
||||
RATE_3_4 = 0b1110_1110_1110_1110_1110_1110_1110_1110,
|
||||
RATE_1_8 = 0b1000_0000_1000_0000_1000_0000_1000_0000,
|
||||
RATE_3_8 = 0b1001_0010_0100_1001_1001_0010_0100_1001,
|
||||
RATE_7_8 = 0b1111_1110_1111_1110_1111_1110_1111_1110,
|
||||
RATE_1_16 = 0b1000_0000_0000_0000_1000_0000_0000_0000,
|
||||
RATE_3_16 = 0b1000_0100_0010_0000_1000_0100_0010_0000,
|
||||
RATE_5_16 = 0b1001_0001_0010_0010_0100_0100_1000_1001,
|
||||
RATE_15_16 = 0b1111_1111_1111_1110_1111_1111_1111_1110,
|
||||
RATE_1_32 = 0b1000_0000_0000_0000_0000_0000_0000_0000,
|
||||
RATE_31_32 = 0b1111_1111_1111_1111_1111_1111_1111_1110,
|
||||
}
|
||||
|
||||
public class Jpeg
|
||||
{
|
||||
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
readonly int timeout = 2000;
|
||||
readonly int taskID;
|
||||
readonly int port;
|
||||
readonly string address;
|
||||
private IPEndPoint ep;
|
||||
|
||||
public Jpeg(string address, int port, int taskID, int timeout = 2000)
|
||||
{
|
||||
if (timeout < 0)
|
||||
throw new ArgumentException("Timeout couldn't be negative", nameof(timeout));
|
||||
this.address = address;
|
||||
this.taskID = taskID;
|
||||
this.port = port;
|
||||
this.ep = new IPEndPoint(IPAddress.Parse(address), port);
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public async ValueTask<bool> SetEnable(bool enable)
|
||||
{
|
||||
var ret = await UDPClientPool.WriteAddr(
|
||||
this.ep, this.taskID, JpegAddr.ENABLE, Convert.ToUInt32(enable), this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to set JPEG enable: {ret.Error}");
|
||||
return false;
|
||||
}
|
||||
return ret.Value;
|
||||
}
|
||||
|
||||
public async ValueTask<bool> SetSampleRate(uint rate)
|
||||
{
|
||||
var ret = await UDPClientPool.WriteAddr(
|
||||
this.ep, this.taskID, JpegAddr.FRAME_SAMPLE_RATE, rate, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to set JPEG sample rate: {ret.Error}");
|
||||
return false;
|
||||
}
|
||||
return ret.Value;
|
||||
}
|
||||
|
||||
public async ValueTask<bool> SetSampleRate(JpegSampleRate rate)
|
||||
{
|
||||
return await SetSampleRate((uint)rate);
|
||||
}
|
||||
|
||||
public async ValueTask<uint> GetFrameNumber()
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddrByte(
|
||||
this.ep, this.taskID, JpegAddr.FRAME_NUM, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to get JPEG frame number: {ret.Error}");
|
||||
return 0;
|
||||
}
|
||||
return Number.BytesToUInt32(ret.Value.Options.Data ?? Array.Empty<byte>()).Value;
|
||||
}
|
||||
|
||||
public async ValueTask<Optional<List<JpegInfo>>> GetFrameInfo(int num)
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, this.taskID, JpegAddr.FRAME_INFO, num, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to get JPEG frame info: {ret.Error}");
|
||||
return new(null);
|
||||
}
|
||||
|
||||
var data = ret.Value.Options.Data;
|
||||
if (data == null || data.Length == 0)
|
||||
{
|
||||
logger.Error($"Data is null or empty");
|
||||
return new(null);
|
||||
}
|
||||
if (data.Length != num * 2)
|
||||
{
|
||||
logger.Error(
|
||||
$"Data length should be {num * 2} bytes, instead of {data.Length} bytes");
|
||||
return new(null);
|
||||
}
|
||||
|
||||
var infos = new List<JpegInfo>();
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
infos.Add(new JpegInfo(data[i..(i + 1)]));
|
||||
}
|
||||
return new(infos);
|
||||
}
|
||||
|
||||
public async ValueTask<bool> UpdatePointer(uint cnt)
|
||||
{
|
||||
var ret = await UDPClientPool.WriteAddr(
|
||||
this.ep, this.taskID, JpegAddr.FRAME_DATA_MAX_POINTER, cnt, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to update pointer: {ret.Error}");
|
||||
return false;
|
||||
}
|
||||
return ret.Value;
|
||||
}
|
||||
|
||||
public async ValueTask<Result<byte[]?>> GetFrame(uint offset, uint length)
|
||||
{
|
||||
if (!MsgBus.IsRunning)
|
||||
{
|
||||
logger.Error("Message bus is not running");
|
||||
return new(new Exception("Message bus is not running"));
|
||||
}
|
||||
MsgBus.UDPServer.ClearUDPData(this.ep.Address.ToString(), this.ep.Port);
|
||||
|
||||
var firstReadLength = (int)(Math.Min(length, JpegAddr.DDR_FRAME_DATA_MAX_ADDR - offset));
|
||||
var secondReadLength = (int)(length - firstReadLength);
|
||||
var dataBytes = new byte[length];
|
||||
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr4Bytes(
|
||||
this.ep, this.taskID, JpegAddr.DDR_FRAME_DATA_ADDR + offset, firstReadLength, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to get JPEG frame data: {ret.Error}");
|
||||
return null;
|
||||
}
|
||||
if (ret.Value.Length != firstReadLength)
|
||||
{
|
||||
logger.Error($"Data length should be {firstReadLength} bytes, instead of {ret.Value.Length} bytes");
|
||||
return null;
|
||||
}
|
||||
Buffer.BlockCopy(ret.Value, 0, dataBytes, 0, firstReadLength);
|
||||
}
|
||||
|
||||
if (secondReadLength > 0)
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr4Bytes(
|
||||
this.ep, this.taskID, JpegAddr.DDR_FRAME_DATA_ADDR, secondReadLength, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to get JPEG frame data: {ret.Error}");
|
||||
return null;
|
||||
}
|
||||
if (ret.Value.Length != secondReadLength)
|
||||
{
|
||||
logger.Error($"Data length should be {secondReadLength} bytes, instead of {ret.Value.Length} bytes");
|
||||
return null;
|
||||
}
|
||||
Buffer.BlockCopy(ret.Value, 0, dataBytes, firstReadLength, secondReadLength);
|
||||
}
|
||||
|
||||
return dataBytes;
|
||||
}
|
||||
|
||||
public async ValueTask<List<byte[]>> GetMultiFrames(uint offset, uint[] sizes)
|
||||
{
|
||||
var frames = new List<byte[]>();
|
||||
for (int i = 0; i < sizes.Length; i++)
|
||||
{
|
||||
var ret = await GetFrame(offset, sizes[i]);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to get JPEG frame {i} data: {ret.Error}");
|
||||
continue;
|
||||
}
|
||||
if (ret.Value == null)
|
||||
{
|
||||
logger.Error($"Frame {i} data is null");
|
||||
continue;
|
||||
}
|
||||
if (ret.Value.Length != sizes[i])
|
||||
{
|
||||
logger.Error(
|
||||
$"Frame {i} data length should be {sizes[i]} bytes, instead of {ret.Value.Length} bytes");
|
||||
continue;
|
||||
}
|
||||
|
||||
frames.Add(ret.Value);
|
||||
offset += sizes[i];
|
||||
}
|
||||
|
||||
{
|
||||
var ret = await UpdatePointer((uint)sizes.Length);
|
||||
if (!ret) logger.Error($"Failed to update pointer");
|
||||
}
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
public async ValueTask<Result<List<byte[]>?>> GetMultiFrames(uint offset)
|
||||
{
|
||||
if (!MsgBus.IsRunning)
|
||||
{
|
||||
logger.Error("Message bus is not running");
|
||||
return new(new Exception("Message bus is not running"));
|
||||
}
|
||||
MsgBus.UDPServer.ClearUDPData(this.ep.Address.ToString(), this.ep.Port);
|
||||
|
||||
var frameNum = await GetFrameNumber();
|
||||
if (frameNum == 0) return null;
|
||||
|
||||
List<uint>? frameSizes = null;
|
||||
{
|
||||
var ret = await GetFrameInfo((int)frameNum);
|
||||
if (!ret.HasValue || ret.Value.Count == 0)
|
||||
{
|
||||
logger.Error($"Failed to get frame info");
|
||||
return null;
|
||||
}
|
||||
frameSizes = ret.Value.Select(x => x.Size).ToList();
|
||||
}
|
||||
|
||||
var frames = await GetMultiFrames(offset, frameSizes.ToArray());
|
||||
if (frames.Count == 0)
|
||||
{
|
||||
logger.Error($"Failed to get frames");
|
||||
return null;
|
||||
}
|
||||
|
||||
return frames;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ using System.Collections;
|
||||
using System.Net;
|
||||
using DotNext;
|
||||
using Newtonsoft.Json;
|
||||
using server;
|
||||
using server.Services;
|
||||
using WebProtocol;
|
||||
|
||||
namespace Peripherals.JtagClient;
|
||||
@@ -442,11 +442,12 @@ public class Jtag
|
||||
return Convert.ToUInt32(Common.Number.BytesToUInt32(retPackOpts.Data).Value);
|
||||
}
|
||||
|
||||
async ValueTask<Result<bool>> WriteFIFO
|
||||
(UInt32 devAddr, UInt32 data, UInt32 result, UInt32 resultMask = 0xFF_FF_FF_FF, UInt32 delayMilliseconds = 0)
|
||||
async ValueTask<Result<bool>> WriteFIFO(
|
||||
UInt32 devAddr, UInt32 data, UInt32 result,
|
||||
UInt32 resultMask = 0xFF_FF_FF_FF, UInt32 delayMilliseconds = 0, ProgressReporter? progress = null)
|
||||
{
|
||||
{
|
||||
var ret = await UDPClientPool.WriteAddr(this.ep, 0, devAddr, data, this.timeout);
|
||||
var ret = await UDPClientPool.WriteAddr(this.ep, 0, devAddr, data, this.timeout, progress?.CreateChild(80));
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
if (!ret.Value) return new(new Exception("Write FIFO failed"));
|
||||
}
|
||||
@@ -457,15 +458,17 @@ public class Jtag
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddrWithWait(this.ep, 0, JtagAddr.STATE, result, resultMask, 0, this.timeout);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
progress?.Finish();
|
||||
return ret.Value;
|
||||
}
|
||||
}
|
||||
|
||||
async ValueTask<Result<bool>> WriteFIFO
|
||||
(UInt32 devAddr, byte[] data, UInt32 result, UInt32 resultMask = 0xFF_FF_FF_FF, UInt32 delayMilliseconds = 0)
|
||||
async ValueTask<Result<bool>> WriteFIFO(
|
||||
UInt32 devAddr, byte[] data, UInt32 result,
|
||||
UInt32 resultMask = 0xFF_FF_FF_FF, UInt32 delayMilliseconds = 0, ProgressReporter? progress = null)
|
||||
{
|
||||
{
|
||||
var ret = await UDPClientPool.WriteAddr(this.ep, 0, devAddr, data, this.timeout);
|
||||
var ret = await UDPClientPool.WriteAddr(this.ep, 0, devAddr, data, this.timeout, progress?.CreateChild(80));
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
if (!ret.Value) return new(new Exception("Write FIFO failed"));
|
||||
}
|
||||
@@ -476,6 +479,7 @@ public class Jtag
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddrWithWait(this.ep, 0, JtagAddr.STATE, result, resultMask, 0, this.timeout);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
progress?.Finish();
|
||||
return ret.Value;
|
||||
}
|
||||
}
|
||||
@@ -559,7 +563,8 @@ public class Jtag
|
||||
return await ClearWriteDataReg();
|
||||
}
|
||||
|
||||
async ValueTask<Result<bool>> LoadDRCareInput(byte[] bytesArray, UInt32 timeout = 10_000, UInt32 cycle = 500)
|
||||
async ValueTask<Result<bool>> LoadDRCareInput(
|
||||
byte[] bytesArray, UInt32 timeout = 10_000, UInt32 cycle = 500, ProgressReporter? progress = null)
|
||||
{
|
||||
var bytesLen = ((uint)(bytesArray.Length * 8));
|
||||
if (bytesLen > Math.Pow(2, 28)) return new(new Exception("Length is over 2^(28 - 3)"));
|
||||
@@ -574,11 +579,15 @@ public class Jtag
|
||||
else if (!ret.Value) return new(new Exception("Write CMD_JTAG_LOAD_DR_CAREI Failed"));
|
||||
}
|
||||
|
||||
progress?.Report(10);
|
||||
|
||||
{
|
||||
var ret = await WriteFIFO(
|
||||
JtagAddr.WRITE_DATA,
|
||||
bytesArray, 0x01_00_00_00,
|
||||
JtagState.CMD_EXEC_FINISH);
|
||||
JtagState.CMD_EXEC_FINISH,
|
||||
progress: progress?.CreateChild(90)
|
||||
);
|
||||
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
return ret.Value;
|
||||
@@ -701,44 +710,55 @@ public class Jtag
|
||||
/// </summary>
|
||||
/// <param name="bitstream">比特流数据</param>
|
||||
/// <returns>指示下载是否成功的异步结果</returns>
|
||||
public async ValueTask<Result<bool>> DownloadBitstream(byte[] bitstream)
|
||||
public async ValueTask<Result<bool>> DownloadBitstream(byte[] bitstream, ProgressReporter? progress = null)
|
||||
{
|
||||
// Clear Data
|
||||
MsgBus.UDPServer.ClearUDPData(this.address, 0);
|
||||
|
||||
logger.Trace($"Clear up udp server {this.address,0} receive data");
|
||||
if (progress != null)
|
||||
{
|
||||
progress.ExpectedSteps = 25;
|
||||
progress.Increase();
|
||||
}
|
||||
|
||||
Result<bool> ret;
|
||||
|
||||
ret = await CloseTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Close Test Failed"));
|
||||
progress?.Increase();
|
||||
|
||||
ret = await RunTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Run Test Failed"));
|
||||
progress?.Increase();
|
||||
|
||||
logger.Trace("Jtag initialize");
|
||||
|
||||
ret = await ExecRDCmd(JtagCmd.JTAG_DR_JRST);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Execute Command JTAG_DR_JRST Failed"));
|
||||
progress?.Increase();
|
||||
|
||||
ret = await RunTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Run Test Failed"));
|
||||
progress?.Increase();
|
||||
|
||||
ret = await ExecRDCmd(JtagCmd.JTAG_DR_CFGI);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Execute Command JTAG_DR_CFGI Failed"));
|
||||
progress?.Increase();
|
||||
|
||||
logger.Trace("Jtag ready to write bitstream");
|
||||
|
||||
ret = await IdleDelay(100000);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag IDLE Delay Failed"));
|
||||
progress?.Increase();
|
||||
|
||||
ret = await LoadDRCareInput(bitstream);
|
||||
ret = await LoadDRCareInput(bitstream, progress: progress?.CreateChild(50));
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Load Data Failed"));
|
||||
|
||||
@@ -747,32 +767,40 @@ public class Jtag
|
||||
ret = await CloseTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Close Test Failed"));
|
||||
progress?.Increase();
|
||||
|
||||
ret = await RunTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Run Test Failed"));
|
||||
progress?.Increase();
|
||||
|
||||
ret = await ExecRDCmd(JtagCmd.JTAG_DR_JWAKEUP);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Execute Command JTAG_DR_JWAKEUP Failed"));
|
||||
progress?.Increase();
|
||||
|
||||
logger.Trace("Jtag reset device");
|
||||
|
||||
ret = await IdleDelay(10000);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag IDLE Delay Failed"));
|
||||
progress?.Increase();
|
||||
|
||||
var retCode = await ReadStatusReg();
|
||||
if (!retCode.IsSuccessful) return new(retCode.Error);
|
||||
var jtagStatus = new JtagStatusReg(retCode.Value);
|
||||
if (!(jtagStatus.done && jtagStatus.wakeup_over && jtagStatus.init_complete))
|
||||
return new(new Exception("Jtag download bitstream failed"));
|
||||
progress?.Increase();
|
||||
|
||||
ret = await CloseTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Close Test Failed"));
|
||||
logger.Trace("Jtag download bitstream successfully");
|
||||
progress?.Increase();
|
||||
|
||||
// Finish
|
||||
progress?.Finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ static class AnalyzerAddr
|
||||
const UInt32 DMA1_BASE = 0x7000_0000;
|
||||
const UInt32 DDR_BASE = 0x0000_0000;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0000 R/W [ 0] capture on: 置1开始等待捕获,0停止捕获。捕获到信号后该位自动清零。 <br/>
|
||||
/// [ 8] capture force: 置1则强制捕获信号,自动置0。 <br/>
|
||||
/// [16] capture busy: 1为逻辑分析仪正在捕获信号。 <br/>
|
||||
@@ -21,7 +21,7 @@ static class AnalyzerAddr
|
||||
/// </summary>
|
||||
public const UInt32 CAPTURE_MODE = BASE + 0x0000_0000;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0001 R/W [1:0] global trig mode: 00: 全局与 (&) <br/>
|
||||
/// 01: 全局或 (|) <br/>
|
||||
/// 10: 全局非与(~&) <br/>
|
||||
@@ -29,7 +29,7 @@ static class AnalyzerAddr
|
||||
/// </summary>
|
||||
public const UInt32 GLOBAL_TRIG_MODE = BASE + 0x0000_0001;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0010 - 0x0000_0017 R/W [5:0] 信号M的触发操作符,共8路 <br/>
|
||||
/// [5:3] M's Operator: 000 == <br/>
|
||||
/// 001 != <br/>
|
||||
@@ -67,12 +67,13 @@ static class AnalyzerAddr
|
||||
public const UInt32 LOAD_NUM_ADDR = BASE + 0x0000_0002;
|
||||
public const UInt32 PRE_LOAD_NUM_ADDR = BASE + 0x0000_0003;
|
||||
public const UInt32 CAHNNEL_DIV_ADDR = BASE + 0x0000_0004;
|
||||
public const UInt32 CLOCK_DIV_ADDR = BASE + 0x0000_0005;
|
||||
public const UInt32 DMA1_START_WRITE_ADDR = DMA1_BASE + 0x0000_0012;
|
||||
public const UInt32 DMA1_END_WRITE_ADDR = DMA1_BASE + 0x0000_0013;
|
||||
public const UInt32 DMA1_CAPTURE_CTRL_ADDR = DMA1_BASE + 0x0000_0014;
|
||||
public const UInt32 STORE_OFFSET_ADDR = DDR_BASE + 0x0010_0000;
|
||||
public const UInt32 STORE_OFFSET_ADDR = DDR_BASE + 0x0100_0000;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0100_0000 - 0x0100_03FF 只读 32位波形存储,得到的32位数据中低八位最先捕获,高八位最后捕获。<br/>
|
||||
/// 共1024个地址,每个地址存储4组,深度为4096。<br/>
|
||||
/// </summary>
|
||||
@@ -86,84 +87,130 @@ static class AnalyzerAddr
|
||||
[Flags]
|
||||
public enum CaptureStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 无状态标志
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 捕获使能位,置1开始等待捕获,0停止捕获。捕获到信号后该位自动清零
|
||||
/// </summary>
|
||||
CaptureOn = 1 << 0, // [0] 捕获使能
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 强制捕获位,置1则强制捕获信号,自动置0
|
||||
/// </summary>
|
||||
CaptureForce = 1 << 8, // [8] 强制捕获
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 捕获忙碌位,1为逻辑分析仪正在捕获信号
|
||||
/// </summary>
|
||||
CaptureBusy = 1 << 16, // [16] 捕获进行中
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 捕获完成位,1为逻辑分析仪内存完整存储了此次捕获的信号
|
||||
/// </summary>
|
||||
CaptureDone = 1 << 24 // [24] 捕获完成
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 全局触发模式枚举,定义多路信号触发条件的逻辑组合方式
|
||||
/// </summary>
|
||||
public enum GlobalCaptureMode
|
||||
{
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 全局与模式,所有触发条件都必须满足
|
||||
/// </summary>
|
||||
AND = 0b00,
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 全局或模式,任一触发条件满足即可
|
||||
/// </summary>
|
||||
OR = 0b01,
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 全局非与模式,不是所有触发条件都满足
|
||||
/// </summary>
|
||||
NAND = 0b10,
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 全局非或模式,所有触发条件都不满足
|
||||
/// </summary>
|
||||
NOR = 0b11
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 逻辑分析仪采样时钟分频系数
|
||||
/// </summary>
|
||||
public enum AnalyzerClockDiv
|
||||
{
|
||||
/// <summary>
|
||||
/// 1分频
|
||||
/// </summary>
|
||||
DIV1 = 0x0000_0000,
|
||||
|
||||
/// <summary>
|
||||
/// 2分频
|
||||
/// </summary>
|
||||
DIV2 = 0x0000_0001,
|
||||
|
||||
/// <summary>
|
||||
/// 4分频
|
||||
/// </summary>
|
||||
DIV4 = 0x0000_0002,
|
||||
|
||||
/// <summary>
|
||||
/// 8分频
|
||||
/// </summary>
|
||||
DIV8 = 0x0000_0003,
|
||||
|
||||
/// <summary>
|
||||
/// 16分频
|
||||
/// </summary>
|
||||
DIV16 = 0x0000_0004,
|
||||
|
||||
/// <summary>
|
||||
/// 32分频
|
||||
/// </summary>
|
||||
DIV32 = 0x0000_0005,
|
||||
|
||||
/// <summary>
|
||||
/// 64分频
|
||||
/// </summary>
|
||||
DIV64 = 0x0000_0006,
|
||||
|
||||
/// <summary>
|
||||
/// 128分频
|
||||
/// </summary>
|
||||
DIV128 = 0x0000_0007
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 信号M的操作符枚举
|
||||
/// </summary>
|
||||
public enum SignalOperator : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 等于操作符
|
||||
/// </summary>
|
||||
Equal = 0b000, // ==
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 不等于操作符
|
||||
/// </summary>
|
||||
NotEqual = 0b001, // !=
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 小于操作符
|
||||
/// </summary>
|
||||
LessThan = 0b010, // <
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 小于等于操作符
|
||||
/// </summary>
|
||||
LessThanOrEqual = 0b011, // <=
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 大于操作符
|
||||
/// </summary>
|
||||
GreaterThan = 0b100, // >
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 大于等于操作符
|
||||
/// </summary>
|
||||
GreaterThanOrEqual = 0b101 // >=
|
||||
@@ -174,35 +221,35 @@ public enum SignalOperator : byte
|
||||
/// </summary>
|
||||
public enum SignalValue : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 逻辑0电平
|
||||
/// </summary>
|
||||
Logic0 = 0b000, // LOGIC 0
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 逻辑1电平
|
||||
/// </summary>
|
||||
Logic1 = 0b001, // LOGIC 1
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 不关心该信号状态
|
||||
/// </summary>
|
||||
NotCare = 0b010, // X(not care)
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 上升沿触发
|
||||
/// </summary>
|
||||
Rise = 0b011, // RISE
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 下降沿触发
|
||||
/// </summary>
|
||||
Fall = 0b100, // FALL
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 上升沿或下降沿触发
|
||||
/// </summary>
|
||||
RiseOrFall = 0b101, // RISE OR FALL
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 信号无变化
|
||||
/// </summary>
|
||||
NoChange = 0b110, // NOCHANGE
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 特定数值
|
||||
/// </summary>
|
||||
SomeNumber = 0b111 // SOME NUMBER
|
||||
@@ -213,11 +260,11 @@ public enum SignalValue : byte
|
||||
/// </summary>
|
||||
public enum AnalyzerChannelDiv
|
||||
{
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 1路
|
||||
/// </summary>
|
||||
ONE = 0x0000_0000,
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 2路
|
||||
/// </summary>
|
||||
TWO = 0x0000_0001,
|
||||
@@ -319,7 +366,7 @@ public class Analyzer
|
||||
/// <returns>操作结果,成功返回寄存器值,否则返回异常信息</returns>
|
||||
public async ValueTask<Result<CaptureStatus>> ReadCaptureStatus()
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, this.taskID, AnalyzerAddr.CAPTURE_MODE, this.timeout);
|
||||
var ret = await UDPClientPool.ReadAddrByte(this.ep, this.taskID, AnalyzerAddr.CAPTURE_MODE, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to read capture status: {ret.Error}");
|
||||
@@ -387,13 +434,14 @@ public class Analyzer
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置逻辑分析仪的深度、预采样深度、有效通道
|
||||
/// 设置逻辑分析仪的深度、预采样深度、有效通道、分频系数
|
||||
/// </summary>
|
||||
/// <param name="capture_length">深度</param>
|
||||
/// <param name="pre_capture_length">预采样深度</param>
|
||||
/// <param name="channel_div">有效通道(0-[1],1-[2],2-[4],3-[8],4-[16],5-[32])</param>
|
||||
/// <param name="clock_div">采样时钟分频系数</param>
|
||||
/// <returns>操作结果,成功返回true,否则返回异常信息</returns>
|
||||
public async ValueTask<Result<bool>> SetCaptureParams(int capture_length, int pre_capture_length, AnalyzerChannelDiv channel_div)
|
||||
public async ValueTask<Result<bool>> SetCaptureParams(int capture_length, int pre_capture_length, AnalyzerChannelDiv channel_div, AnalyzerClockDiv clock_div)
|
||||
{
|
||||
if (capture_length == 0) capture_length = 1;
|
||||
if (pre_capture_length == 0) pre_capture_length = 1;
|
||||
@@ -462,6 +510,19 @@ public class Analyzer
|
||||
return new(new Exception("Failed to set CAHNNEL_DIV_ADDR"));
|
||||
}
|
||||
}
|
||||
{
|
||||
var ret = await UDPClientPool.WriteAddr(this.ep, this.taskID, AnalyzerAddr.CLOCK_DIV_ADDR, (UInt32)clock_div, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to set CLOCK_DIV_ADDR: {ret.Error}");
|
||||
return new(ret.Error);
|
||||
}
|
||||
if (!ret.Value)
|
||||
{
|
||||
logger.Error("WriteAddr to CLOCK_DIV_ADDR returned false");
|
||||
return new(new Exception("Failed to set CLOCK_DIV_ADDR"));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,57 +9,57 @@ static class OscilloscopeAddr
|
||||
{
|
||||
const UInt32 BASE = 0x8000_0000;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0000:R/W[0] wave_run 启动捕获/关闭
|
||||
/// </summary>
|
||||
public const UInt32 START_CAPTURE = BASE + 0x0000_0000;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0001: R/W[7:0] trig_level 触发电平
|
||||
/// </summary>
|
||||
public const UInt32 TRIG_LEVEL = BASE + 0x0000_0001;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0002:R/W[0] trig_edge 触发边沿,0-下降沿,1-上升沿
|
||||
/// </summary>
|
||||
public const UInt32 TRIG_EDGE = BASE + 0x0000_0002;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0003: R/W[9:0] h shift 水平偏移量
|
||||
/// </summary>
|
||||
public const UInt32 H_SHIFT = BASE + 0x0000_0003;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0004: R/W[9:0] deci rate 抽样率,0—1023
|
||||
/// </summary>
|
||||
public const UInt32 DECI_RATE = BASE + 0x0000_0004;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0005:R/W[0] ram refresh RAM刷新
|
||||
/// </summary>
|
||||
public const UInt32 RAM_FRESH = BASE + 0x0000_0005;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000 0006:R[19: 0] ad_freq AD采样频率
|
||||
/// </summary>
|
||||
public const UInt32 AD_FREQ = BASE + 0x0000_0006;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Ox0000_0007: R[7:0] ad_vpp AD采样幅度
|
||||
/// </summary>
|
||||
public const UInt32 AD_VPP = BASE + 0x0000_0007;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0008: R[7:0] ad max AD采样最大值
|
||||
/// </summary>
|
||||
public const UInt32 AD_MAX = BASE + 0x0000_0008;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_0009: R[7:0] ad_min AD采样最小值
|
||||
/// </summary>
|
||||
public const UInt32 AD_MIN = BASE + 0x0000_0009;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 0x0000_1000-0x0000_13FF:R[7:0] wave_rd_data 共1024个字节
|
||||
/// </summary>
|
||||
public const UInt32 RD_DATA_ADDR = BASE + 0x0000_1000;
|
||||
@@ -232,7 +232,7 @@ class Oscilloscope
|
||||
/// <returns>操作结果,成功返回采样频率值,否则返回异常信息</returns>
|
||||
public async ValueTask<Result<UInt32>> GetADFrequency()
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, this.taskID, OscilloscopeAddr.AD_FREQ, this.timeout);
|
||||
var ret = await UDPClientPool.ReadAddrByte(this.ep, this.taskID, OscilloscopeAddr.AD_FREQ, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to read AD frequency: {ret.Error}");
|
||||
@@ -255,7 +255,7 @@ class Oscilloscope
|
||||
/// <returns>操作结果,成功返回采样幅度值,否则返回异常信息</returns>
|
||||
public async ValueTask<Result<byte>> GetADVpp()
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, this.taskID, OscilloscopeAddr.AD_VPP, this.timeout);
|
||||
var ret = await UDPClientPool.ReadAddrByte(this.ep, this.taskID, OscilloscopeAddr.AD_VPP, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to read AD VPP: {ret.Error}");
|
||||
@@ -275,7 +275,7 @@ class Oscilloscope
|
||||
/// <returns>操作结果,成功返回采样最大值,否则返回异常信息</returns>
|
||||
public async ValueTask<Result<byte>> GetADMax()
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, this.taskID, OscilloscopeAddr.AD_MAX, this.timeout);
|
||||
var ret = await UDPClientPool.ReadAddrByte(this.ep, this.taskID, OscilloscopeAddr.AD_MAX, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to read AD max: {ret.Error}");
|
||||
@@ -295,7 +295,7 @@ class Oscilloscope
|
||||
/// <returns>操作结果,成功返回采样最小值,否则返回异常信息</returns>
|
||||
public async ValueTask<Result<byte>> GetADMin()
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, this.taskID, OscilloscopeAddr.AD_MIN, this.timeout);
|
||||
var ret = await UDPClientPool.ReadAddrByte(this.ep, this.taskID, OscilloscopeAddr.AD_MIN, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to read AD min: {ret.Error}");
|
||||
|
||||
@@ -7,20 +7,20 @@ static class RemoteUpdaterAddr
|
||||
{
|
||||
public const UInt32 Base = 0x20_00_00_00;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// ADDR: 0X00: 写Flash-读写地址——控制位 <br/>
|
||||
/// [31:16]: wr_sector_num <br/>
|
||||
/// [15: 0]: {flash_wr_en,-,-,-, start_wr_sector} <br/>
|
||||
/// </summary>
|
||||
public const UInt32 WriteCtrl = Base + 0x00;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// ADDR: 0X01: 写Flash-只写地址——FIFO入口 <br/>
|
||||
/// [31:0]: 写比特流数据入口 <br/>
|
||||
/// </summary>
|
||||
public const UInt32 WriteFIFO = Base + 0x01;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// ADDR: 0X02: 写Flash-只读地址——标志位 <br/>
|
||||
/// [31:24]: {-, -, -, -, -, -, -, wr_fifo_full} <br/>
|
||||
/// [23:16]: {-, -, -, -, -, -, -, wr_fifo_empty} <br/>
|
||||
@@ -29,14 +29,14 @@ static class RemoteUpdaterAddr
|
||||
/// </summary>
|
||||
public const UInt32 WriteSign = Base + 0x02;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// ADDR: 0X03: 读Flash-读写地址——控制位1 <br/>
|
||||
/// [31:16]: rd_sector_num <br/>
|
||||
/// [15: 0]: {flash_rd_en,-,-,-, start_rd_sub_sector} <br/>
|
||||
/// </summary>
|
||||
public const UInt32 ReadCtrl1 = Base + 0x03;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// ADDR: 0X04: 读Flash-读写地址——控制位2 <br/>
|
||||
/// [31:24]: { } <br/>
|
||||
/// [23:16]: {-, -, -, -, -, -,{ bs_crc32_ok }} <br/>
|
||||
@@ -45,19 +45,19 @@ static class RemoteUpdaterAddr
|
||||
/// </summary>
|
||||
public const UInt32 ReadCtrl2 = Base + 0x04;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// ADDR: 0X05: 读Flash-只读地址——FIFO出口 <br/>
|
||||
/// [31:0]: 读比特流数据出口 <br/>
|
||||
/// </summary>
|
||||
public const UInt32 ReadFIFO = Base + 0x05;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// ADDR: 0X06: 读Flash-只读地址——CRC校验值 <br/>
|
||||
/// [31:0]: CRC校验值 bs_readback_crc <br/>
|
||||
/// </summary>
|
||||
public const UInt32 ReadCRC = Base + 0x06;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// ADDR: 0X07: 读Flash-只读地址——标志位 <br/>
|
||||
/// [31:24]: {-, -, -, -, -, -, -, rd_fifo_afull} <br/>
|
||||
/// [23:16]: {-, -, -, -, -, -, -, rd_fifo_empty} <br/>
|
||||
@@ -66,14 +66,14 @@ static class RemoteUpdaterAddr
|
||||
/// </summary>
|
||||
public const UInt32 ReadSign = Base + 0x07;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// ADDR: 0X08: 热启动开关-读写地址——控制位 <br/>
|
||||
/// [31: 8]: hotreset_addr <br/>
|
||||
/// [ 7: 0]: {-, -, -, -, -, -, -, hotreset_en} <br/>
|
||||
/// </summary>
|
||||
public const UInt32 HotResetCtrl = Base + 0x08;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// ADDR: 0X09: 只读地址 版本号 <br/>
|
||||
/// [31: 0]: FPGA_VERSION[31:0] <br/>
|
||||
/// </summary>
|
||||
@@ -339,7 +339,7 @@ public class RemoteUpdater
|
||||
}
|
||||
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, 0, RemoteUpdaterAddr.ReadCRC, this.timeout);
|
||||
var ret = await UDPClientPool.ReadAddrByte(this.ep, 0, RemoteUpdaterAddr.ReadCRC, this.timeout);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
|
||||
var bytes = ret.Value.Options.Data;
|
||||
@@ -543,7 +543,7 @@ public class RemoteUpdater
|
||||
logger.Trace("Clear udp data finished");
|
||||
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, 0, RemoteUpdaterAddr.Version, this.timeout);
|
||||
var ret = await UDPClientPool.ReadAddrByte(this.ep, 0, RemoteUpdaterAddr.Version, this.timeout);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
|
||||
var retData = ret.Value.Options.Data;
|
||||
|
||||
403
server/src/Services/HttpHdmiVideoStreamService.cs
Normal file
403
server/src/Services/HttpHdmiVideoStreamService.cs
Normal file
@@ -0,0 +1,403 @@
|
||||
using System.Net;
|
||||
using System.Collections.Concurrent;
|
||||
using Peripherals.HdmiInClient;
|
||||
|
||||
namespace server.Services;
|
||||
|
||||
public class HdmiVideoStreamEndpoint
|
||||
{
|
||||
public string BoardId { get; set; } = "";
|
||||
public string MjpegUrl { get; set; } = "";
|
||||
public string VideoUrl { get; set; } = "";
|
||||
public string SnapshotUrl { get; set; } = "";
|
||||
}
|
||||
|
||||
public class HttpHdmiVideoStreamService : BackgroundService
|
||||
{
|
||||
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
private HttpListener? _httpListener;
|
||||
private readonly int _serverPort = 4322;
|
||||
private readonly ConcurrentDictionary<string, HdmiIn> _hdmiInDict = new();
|
||||
private readonly ConcurrentDictionary<string, CancellationTokenSource> _hdmiInCtsDict = new();
|
||||
|
||||
public override async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_httpListener = new HttpListener();
|
||||
_httpListener.Prefixes.Add($"http://{Global.localhost}:{_serverPort}/");
|
||||
_httpListener.Start();
|
||||
logger.Info($"HDMI Video Stream Service started on port {_serverPort}");
|
||||
|
||||
await base.StartAsync(cancellationToken);
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
if (_httpListener == null) continue;
|
||||
try
|
||||
{
|
||||
logger.Debug("Waiting for HTTP request...");
|
||||
var contextTask = _httpListener.GetContextAsync();
|
||||
var completedTask = await Task.WhenAny(contextTask, Task.Delay(-1, stoppingToken));
|
||||
if (completedTask == contextTask)
|
||||
{
|
||||
var context = contextTask.Result;
|
||||
logger.Debug($"Received request: {context.Request.Url?.AbsolutePath}");
|
||||
if (context != null)
|
||||
_ = HandleRequestAsync(context, stoppingToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "Error in GetContextAsync");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
logger.Info("Stopping HDMI Video Stream Service...");
|
||||
_httpListener?.Close();
|
||||
|
||||
// 禁用所有活跃的HDMI传输
|
||||
var disableTasks = new List<Task>();
|
||||
foreach (var hdmiKey in _hdmiInDict.Keys)
|
||||
{
|
||||
disableTasks.Add(DisableHdmiTransmissionAsync(hdmiKey));
|
||||
}
|
||||
|
||||
// 等待所有禁用操作完成
|
||||
await Task.WhenAll(disableTasks);
|
||||
|
||||
// 清空字典
|
||||
_hdmiInDict.Clear();
|
||||
_hdmiInCtsDict.Clear();
|
||||
|
||||
_httpListener?.Close(); // 立即关闭监听器,唤醒阻塞
|
||||
await base.StopAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task DisableHdmiTransmissionAsync(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
var cts = _hdmiInCtsDict[key];
|
||||
cts.Cancel();
|
||||
|
||||
var hdmiIn = _hdmiInDict[key];
|
||||
var disableResult = await hdmiIn.EnableTrans(false);
|
||||
if (disableResult.IsSuccessful)
|
||||
{
|
||||
logger.Info("Successfully disabled HDMI transmission");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error($"Failed to disable HDMI transmission: {disableResult.Error}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "Exception occurred while disabling HDMI transmission");
|
||||
}
|
||||
}
|
||||
|
||||
// 获取/创建 HdmiIn 实例
|
||||
private async Task<HdmiIn?> GetOrCreateHdmiInAsync(string boardId)
|
||||
{
|
||||
if (_hdmiInDict.TryGetValue(boardId, out var hdmiIn))
|
||||
{
|
||||
try
|
||||
{
|
||||
var enableResult = await hdmiIn.EnableTrans(true);
|
||||
if (!enableResult.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to enable HDMI transmission for board {boardId}: {enableResult.Error}");
|
||||
return null;
|
||||
}
|
||||
logger.Info($"Successfully enabled HDMI transmission for board {boardId}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, $"Exception occurred while enabling HDMI transmission for board {boardId}");
|
||||
return null;
|
||||
}
|
||||
|
||||
_hdmiInDict[boardId] = hdmiIn;
|
||||
_hdmiInCtsDict[boardId] = new CancellationTokenSource();
|
||||
return hdmiIn;
|
||||
}
|
||||
|
||||
var db = new Database.AppDataConnection();
|
||||
if (db == null)
|
||||
{
|
||||
logger.Error("Failed to create HdmiIn instance");
|
||||
return null;
|
||||
}
|
||||
|
||||
var boardRet = db.GetBoardByID(Guid.Parse(boardId));
|
||||
if (!boardRet.IsSuccessful || !boardRet.Value.HasValue)
|
||||
{
|
||||
logger.Error($"Failed to get board with ID {boardId}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var board = boardRet.Value.Value;
|
||||
|
||||
hdmiIn = new HdmiIn(board.IpAddr, board.Port, 0); // taskID 可根据实际需求调整
|
||||
|
||||
// 启用HDMI传输
|
||||
try
|
||||
{
|
||||
var enableResult = await hdmiIn.EnableTrans(true);
|
||||
if (!enableResult.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to enable HDMI transmission for board {boardId}: {enableResult.Error}");
|
||||
return null;
|
||||
}
|
||||
logger.Info($"Successfully enabled HDMI transmission for board {boardId}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, $"Exception occurred while enabling HDMI transmission for board {boardId}");
|
||||
return null;
|
||||
}
|
||||
|
||||
_hdmiInDict[boardId] = hdmiIn;
|
||||
_hdmiInCtsDict[boardId] = new CancellationTokenSource();
|
||||
return hdmiIn;
|
||||
}
|
||||
|
||||
private async Task HandleRequestAsync(HttpListenerContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
var path = context.Request.Url?.AbsolutePath ?? "/";
|
||||
var boardId = context.Request.QueryString["boardId"];
|
||||
if (string.IsNullOrEmpty(boardId))
|
||||
{
|
||||
await SendErrorAsync(context.Response, "Missing boardId");
|
||||
return;
|
||||
}
|
||||
|
||||
var hdmiIn = await GetOrCreateHdmiInAsync(boardId);
|
||||
if (hdmiIn == null)
|
||||
{
|
||||
await SendErrorAsync(context.Response, "Invalid boardId or board not available");
|
||||
return;
|
||||
}
|
||||
|
||||
var hdmiInToken = _hdmiInCtsDict[boardId].Token;
|
||||
if (hdmiInToken == null)
|
||||
{
|
||||
await SendErrorAsync(context.Response, "HDMI input is not available");
|
||||
return;
|
||||
}
|
||||
|
||||
if (path == "/snapshot")
|
||||
{
|
||||
await HandleSnapshotRequestAsync(context.Response, hdmiIn, hdmiInToken);
|
||||
}
|
||||
else if (path == "/mjpeg")
|
||||
{
|
||||
await HandleMjpegStreamAsync(context.Response, hdmiIn, hdmiInToken);
|
||||
}
|
||||
else if (path == "/video")
|
||||
{
|
||||
await SendVideoHtmlPageAsync(context.Response, boardId);
|
||||
}
|
||||
else
|
||||
{
|
||||
await SendIndexHtmlPageAsync(context.Response, boardId);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleSnapshotRequestAsync(HttpListenerResponse response, HdmiIn hdmiIn, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Debug("处理HDMI快照请求");
|
||||
|
||||
// 从HDMI读取RGB565数据
|
||||
var frameResult = await hdmiIn.ReadFrame();
|
||||
if (!frameResult.IsSuccessful || frameResult.Value == null)
|
||||
{
|
||||
logger.Error("HDMI快照获取失败");
|
||||
response.StatusCode = 500;
|
||||
var errorBytes = System.Text.Encoding.UTF8.GetBytes("Failed to get HDMI snapshot");
|
||||
await response.OutputStream.WriteAsync(errorBytes, 0, errorBytes.Length, cancellationToken);
|
||||
response.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
var jpegData = frameResult.Value;
|
||||
|
||||
// 设置响应头(参考Camera版本)
|
||||
response.ContentType = "image/jpeg";
|
||||
response.ContentLength64 = jpegData.Length;
|
||||
response.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
|
||||
await response.OutputStream.WriteAsync(jpegData, 0, jpegData.Length, cancellationToken);
|
||||
await response.OutputStream.FlushAsync(cancellationToken);
|
||||
|
||||
logger.Debug("已发送HDMI快照图像,大小:{Size} 字节", jpegData.Length);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "处理HDMI快照请求时出错");
|
||||
response.StatusCode = 500;
|
||||
}
|
||||
finally
|
||||
{
|
||||
response.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleMjpegStreamAsync(HttpListenerResponse response, HdmiIn hdmiIn, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 设置MJPEG流的响应头(参考Camera版本)
|
||||
response.ContentType = "multipart/x-mixed-replace; boundary=--boundary";
|
||||
response.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
response.Headers.Add("Pragma", "no-cache");
|
||||
response.Headers.Add("Expires", "0");
|
||||
|
||||
logger.Debug("开始HDMI MJPEG流传输");
|
||||
|
||||
int frameCounter = 0;
|
||||
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
var frameStartTime = DateTime.UtcNow;
|
||||
|
||||
var ret = await hdmiIn.GetMJpegFrame();
|
||||
if (ret == null) continue;
|
||||
var frame = ret.Value;
|
||||
|
||||
await response.OutputStream.WriteAsync(frame.header, 0, frame.header.Length, cancellationToken);
|
||||
await response.OutputStream.WriteAsync(frame.data, 0, frame.data.Length, cancellationToken);
|
||||
await response.OutputStream.WriteAsync(frame.footer, 0, frame.footer.Length, cancellationToken);
|
||||
await response.OutputStream.FlushAsync(cancellationToken);
|
||||
|
||||
frameCounter++;
|
||||
|
||||
var totalTime = (DateTime.UtcNow - frameStartTime).TotalMilliseconds;
|
||||
|
||||
// 性能统计日志(每30帧记录一次)
|
||||
if (frameCounter % 30 == 0)
|
||||
{
|
||||
logger.Debug("HDMI帧 {FrameNumber} 性能统计 - 总计: {TotalTime:F1}ms, JPEG大小: {JpegSize} 字节",
|
||||
frameCounter, totalTime, frame.data.Length);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "处理HDMI帧时发生错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "HDMI MJPEG流处理异常");
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
// 停止传输时禁用HDMI传输
|
||||
await hdmiIn.EnableTrans(false);
|
||||
logger.Info("已禁用HDMI传输");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "禁用HDMI传输时出错");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
response.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略关闭时的错误
|
||||
}
|
||||
logger.Debug("HDMI MJPEG流连接已关闭");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SendVideoHtmlPageAsync(HttpListenerResponse response, string boardId)
|
||||
{
|
||||
string html = $@"<html><body>
|
||||
<h1>HDMI Video Stream for Board {boardId}</h1>
|
||||
<img src='/mjpeg?boardId={boardId}' />
|
||||
</body></html>";
|
||||
response.ContentType = "text/html";
|
||||
await response.OutputStream.WriteAsync(System.Text.Encoding.UTF8.GetBytes(html));
|
||||
response.Close();
|
||||
}
|
||||
|
||||
private async Task SendIndexHtmlPageAsync(HttpListenerResponse response, string boardId)
|
||||
{
|
||||
string html = $@"<html><body>
|
||||
<h1>Welcome to HDMI Video Stream Service</h1>
|
||||
<a href='/video?boardId={boardId}'>View Video Stream for Board {boardId}</a>
|
||||
</body></html>";
|
||||
response.ContentType = "text/html";
|
||||
await response.OutputStream.WriteAsync(System.Text.Encoding.UTF8.GetBytes(html));
|
||||
response.Close();
|
||||
}
|
||||
|
||||
private async Task SendErrorAsync(HttpListenerResponse response, string message)
|
||||
{
|
||||
response.StatusCode = 400;
|
||||
await response.OutputStream.WriteAsync(System.Text.Encoding.UTF8.GetBytes(message));
|
||||
response.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有可用的HDMI视频流终端点
|
||||
/// </summary>
|
||||
/// <returns>返回所有可用的HDMI视频流终端点列表</returns>
|
||||
public List<HdmiVideoStreamEndpoint>? GetAllVideoEndpoints()
|
||||
{
|
||||
var db = new Database.AppDataConnection();
|
||||
var boards = db?.GetAllBoard();
|
||||
if (boards == null)
|
||||
return null;
|
||||
|
||||
var endpoints = new List<HdmiVideoStreamEndpoint>();
|
||||
foreach (var board in boards)
|
||||
{
|
||||
endpoints.Add(new HdmiVideoStreamEndpoint
|
||||
{
|
||||
BoardId = board.ID.ToString(),
|
||||
MjpegUrl = $"http://{Global.localhost}:{_serverPort}/mjpeg?boardId={board.ID}",
|
||||
VideoUrl = $"http://{Global.localhost}:{_serverPort}/video?boardId={board.ID}",
|
||||
SnapshotUrl = $"http://{Global.localhost}:{_serverPort}/snapshot?boardId={board.ID}"
|
||||
});
|
||||
}
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定板卡ID的HDMI视频流终端点
|
||||
/// </summary>
|
||||
/// <param name="boardId">板卡ID</param>
|
||||
/// <returns>返回指定板卡的HDMI视频流终端点</returns>
|
||||
public HdmiVideoStreamEndpoint GetVideoEndpoint(string boardId)
|
||||
{
|
||||
return new HdmiVideoStreamEndpoint
|
||||
{
|
||||
BoardId = boardId,
|
||||
MjpegUrl = $"http://{Global.localhost}:{_serverPort}/mjpeg?boardId={boardId}",
|
||||
VideoUrl = $"http://{Global.localhost}:{_serverPort}/video?boardId={boardId}",
|
||||
SnapshotUrl = $"http://{Global.localhost}:{_serverPort}/snapshot?boardId={boardId}"
|
||||
};
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
288
server/src/Services/ProgressTrackerService.cs
Normal file
288
server/src/Services/ProgressTrackerService.cs
Normal file
@@ -0,0 +1,288 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System.Collections.Concurrent;
|
||||
using DotNext;
|
||||
using Common;
|
||||
using server.Hubs;
|
||||
|
||||
namespace server.Services;
|
||||
|
||||
public class ProgressReporter : ProgressInfo, IProgress<int>
|
||||
{
|
||||
private int _progress = 0;
|
||||
private int _stepProgress = 1;
|
||||
private int _expectedSteps = 100;
|
||||
private int _parentProportion = 100;
|
||||
|
||||
public int Progress => _progress;
|
||||
public int MaxProgress { get; set; } = 100;
|
||||
public int StepProgress
|
||||
{
|
||||
get => _stepProgress;
|
||||
set
|
||||
{
|
||||
_stepProgress = value;
|
||||
_expectedSteps = MaxProgress / value;
|
||||
}
|
||||
}
|
||||
public int ExpectedSteps
|
||||
{
|
||||
get => _expectedSteps;
|
||||
set
|
||||
{
|
||||
_expectedSteps = value;
|
||||
MaxProgress = Number.IntPow(10, Number.GetLength(value));
|
||||
_stepProgress = MaxProgress / value;
|
||||
}
|
||||
}
|
||||
public Func<int, Task>? ReporterFunc { get; set; } = null;
|
||||
public ProgressReporter? Parent { get; set; }
|
||||
public ProgressReporter? Child { get; set; }
|
||||
|
||||
private ProgressStatus _status = ProgressStatus.Pending;
|
||||
private string _errorMessage;
|
||||
|
||||
public string TaskId { get; set; } = Guid.NewGuid().ToString();
|
||||
public int ProgressPercent => _progress * 100 / MaxProgress;
|
||||
public ProgressStatus Status => _status;
|
||||
public string ErrorMessage => _errorMessage;
|
||||
|
||||
public ProgressReporter(Func<int, Task>? reporter = null, int initProgress = 0, int maxProgress = 100, int step = 1)
|
||||
{
|
||||
_progress = initProgress;
|
||||
MaxProgress = maxProgress;
|
||||
StepProgress = step;
|
||||
ReporterFunc = reporter;
|
||||
}
|
||||
|
||||
public ProgressReporter(int parentProportion, int expectedSteps = 100, Func<int, Task>? reporter = null)
|
||||
{
|
||||
this._parentProportion = parentProportion;
|
||||
MaxProgress = Number.IntPow(10, Number.GetLength(expectedSteps));
|
||||
StepProgress = MaxProgress / expectedSteps;
|
||||
ReporterFunc = reporter;
|
||||
}
|
||||
|
||||
private async void ForceReport(int value)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ReporterFunc != null)
|
||||
await ReporterFunc(value);
|
||||
|
||||
if (Parent != null)
|
||||
Parent.Increase((value - _progress) / StepProgress * _parentProportion / (MaxProgress / StepProgress));
|
||||
|
||||
_progress = value;
|
||||
}
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
_errorMessage = ex.Message;
|
||||
this._status = ProgressStatus.Canceled;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_errorMessage = ex.Message;
|
||||
this._status = ProgressStatus.Failed;
|
||||
}
|
||||
}
|
||||
|
||||
public async void Report(int value)
|
||||
{
|
||||
if (this._status == ProgressStatus.Pending)
|
||||
this._status = ProgressStatus.InProgress;
|
||||
else if (this.Status != ProgressStatus.InProgress)
|
||||
return;
|
||||
|
||||
if (value > MaxProgress) return;
|
||||
ForceReport(value);
|
||||
}
|
||||
|
||||
public void Increase(int? value = null)
|
||||
{
|
||||
if (this._status == ProgressStatus.Pending)
|
||||
this._status = ProgressStatus.InProgress;
|
||||
else if (this.Status != ProgressStatus.InProgress)
|
||||
return;
|
||||
|
||||
if (value.HasValue)
|
||||
{
|
||||
if (_progress + value.Value >= MaxProgress) return;
|
||||
this.Report(_progress + value.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_progress + StepProgress >= MaxProgress) return;
|
||||
this.Report(_progress + StepProgress);
|
||||
}
|
||||
}
|
||||
|
||||
public void Finish()
|
||||
{
|
||||
this._status = ProgressStatus.Completed;
|
||||
this.ForceReport(MaxProgress);
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
this._status = ProgressStatus.Canceled;
|
||||
this._errorMessage = "User Cancelled";
|
||||
this.ForceReport(_progress);
|
||||
}
|
||||
|
||||
public void Error(string message)
|
||||
{
|
||||
this._status = ProgressStatus.Failed;
|
||||
this._errorMessage = message;
|
||||
this.ForceReport(_progress);
|
||||
}
|
||||
|
||||
public ProgressReporter CreateChild(int proportion, int expectedSteps = 100)
|
||||
{
|
||||
var child = new ProgressReporter(proportion, expectedSteps);
|
||||
child.Parent = this;
|
||||
this.Child = child;
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
public class ProgressTrackerService : BackgroundService
|
||||
{
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
private readonly ConcurrentDictionary<string, TaskProgressInfo> _taskMap = new();
|
||||
private readonly IHubContext<ProgressHub, IProgressReceiver> _hubContext;
|
||||
|
||||
private class TaskProgressInfo
|
||||
{
|
||||
public ProgressReporter Reporter { get; set; }
|
||||
public string? ConnectionId { get; set; }
|
||||
public required CancellationToken CancellationToken { get; set; }
|
||||
public required CancellationTokenSource CancellationTokenSource { get; set; }
|
||||
public required DateTime UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
public ProgressTrackerService(IHubContext<ProgressHub, IProgressReceiver> hubContext)
|
||||
{
|
||||
_hubContext = hubContext;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
foreach (var kvp in _taskMap)
|
||||
{
|
||||
var info = kvp.Value;
|
||||
// 超过 1 分钟且任务已完成/失败/取消
|
||||
if ((now - info.UpdatedAt).TotalMinutes > 1 &&
|
||||
(info.Reporter.Status == ProgressStatus.Completed ||
|
||||
info.Reporter.Status == ProgressStatus.Failed ||
|
||||
info.Reporter.Status == ProgressStatus.Canceled))
|
||||
{
|
||||
_taskMap.TryRemove(kvp.Key, out _);
|
||||
logger.Info($"Cleaned up task {kvp.Key}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "Error during ProgressTracker cleanup");
|
||||
}
|
||||
await Task.Delay(TimeSpan.FromSeconds(30), stoppingToken);
|
||||
}
|
||||
}
|
||||
|
||||
public (string, ProgressReporter) CreateTask(CancellationToken? cancellationToken = null)
|
||||
{
|
||||
CancellationTokenSource? cancellationTokenSource;
|
||||
if (cancellationToken.HasValue)
|
||||
{
|
||||
cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
var progressInfo = new TaskProgressInfo
|
||||
{
|
||||
ConnectionId = null,
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
CancellationToken = cancellationTokenSource.Token,
|
||||
CancellationTokenSource = cancellationTokenSource,
|
||||
};
|
||||
|
||||
var progress = new ProgressReporter(async value =>
|
||||
{
|
||||
cancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||
|
||||
// 通过 SignalR 推送进度
|
||||
if (progressInfo.ConnectionId != null)
|
||||
await _hubContext.Clients.Client(progressInfo.ConnectionId).OnReceiveProgress(progressInfo.Reporter);
|
||||
});
|
||||
|
||||
progressInfo.Reporter = progress;
|
||||
|
||||
_taskMap.TryAdd(progressInfo.Reporter.TaskId, progressInfo);
|
||||
|
||||
return (progressInfo.Reporter.TaskId, progress);
|
||||
}
|
||||
|
||||
public Optional<ProgressReporter> GetReporter(string taskId)
|
||||
{
|
||||
if (_taskMap.TryGetValue(taskId, out var info))
|
||||
{
|
||||
return info.Reporter;
|
||||
}
|
||||
return Optional<ProgressReporter>.None;
|
||||
}
|
||||
|
||||
public Optional<ProgressStatus> GetProgressStatus(string taskId)
|
||||
{
|
||||
if (_taskMap.TryGetValue(taskId, out var info))
|
||||
{
|
||||
return info.Reporter.Status;
|
||||
}
|
||||
return Optional<ProgressStatus>.None;
|
||||
}
|
||||
|
||||
public bool BindTask(string taskId, string connectionId)
|
||||
{
|
||||
if (_taskMap.TryGetValue(taskId, out var info) && info != null)
|
||||
{
|
||||
lock (info)
|
||||
{
|
||||
info.ConnectionId = connectionId;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CancelTask(string taskId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_taskMap.TryGetValue(taskId, out var info) && info != null)
|
||||
{
|
||||
lock (info)
|
||||
{
|
||||
info.CancellationTokenSource.Cancel();
|
||||
info.Reporter.Cancel();
|
||||
info.UpdatedAt = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, $"Failed to cancel task {taskId}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using DotNext;
|
||||
using WebProtocol;
|
||||
using server.Services;
|
||||
|
||||
/// <summary>
|
||||
/// UDP客户端发送池
|
||||
@@ -222,22 +223,28 @@ public class UDPClientPool
|
||||
/// <param name="endPoint">IP端点(IP地址与端口)</param>
|
||||
/// <param name="taskID">任务ID</param>
|
||||
/// <param name="devAddr">设备地址</param>
|
||||
/// <param name="dataLength">数据长度(0~255)</param>
|
||||
/// <param name="timeout">超时时间(毫秒)</param>
|
||||
/// <returns>读取结果,包含接收到的数据包</returns>
|
||||
public static async ValueTask<Result<RecvDataPackage>> ReadAddr(
|
||||
IPEndPoint endPoint, int taskID, uint devAddr, int timeout = 1000)
|
||||
IPEndPoint endPoint, int taskID, uint devAddr, int dataLength, int timeout = 1000)
|
||||
{
|
||||
if (dataLength <= 0)
|
||||
return new(new ArgumentException("Data length must be greater than 0"));
|
||||
|
||||
if (dataLength > 255)
|
||||
return new(new ArgumentException("Data length must be less than or equal to 255"));
|
||||
|
||||
var ret = false;
|
||||
var opts = new SendAddrPackOptions()
|
||||
{
|
||||
BurstType = BurstType.FixedBurst,
|
||||
BurstLength = 0,
|
||||
BurstLength = ((byte)(dataLength - 1)),
|
||||
CommandID = Convert.ToByte(taskID),
|
||||
Address = devAddr,
|
||||
IsWrite = false,
|
||||
};
|
||||
|
||||
|
||||
// Read Register
|
||||
ret = await UDPClientPool.SendAddrPackAsync(endPoint, new SendAddrPackage(opts));
|
||||
if (!ret) return new(new Exception("Send Address Package Failed!"));
|
||||
@@ -259,6 +266,20 @@ public class UDPClientPool
|
||||
return retPack;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取设备地址数据
|
||||
/// </summary>
|
||||
/// <param name="endPoint">IP端点(IP地址与端口)</param>
|
||||
/// <param name="taskID">任务ID</param>
|
||||
/// <param name="devAddr">设备地址</param>
|
||||
/// <param name="timeout">超时时间(毫秒)</param>
|
||||
/// <returns>读取结果,包含接收到的数据包</returns>
|
||||
public static async ValueTask<Result<RecvDataPackage>> ReadAddrByte(
|
||||
IPEndPoint endPoint, int taskID, uint devAddr, int timeout = 1000)
|
||||
{
|
||||
return await ReadAddr(endPoint, taskID, devAddr, 0, timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取设备地址数据并校验结果
|
||||
/// </summary>
|
||||
@@ -270,11 +291,11 @@ public class UDPClientPool
|
||||
/// <param name="timeout">超时时间(毫秒)</param>
|
||||
/// <returns>校验结果,true表示数据匹配期望值</returns>
|
||||
public static async ValueTask<Result<bool>> ReadAddr(
|
||||
IPEndPoint endPoint, int taskID, uint devAddr, UInt32 result, UInt32 resultMask, int timeout = 1000)
|
||||
IPEndPoint endPoint, int taskID, uint devAddr, UInt32 result, UInt32 resultMask, int timeout = 1000)
|
||||
{
|
||||
var address = endPoint.Address.ToString();
|
||||
|
||||
var ret = await ReadAddr(endPoint, taskID, devAddr, timeout);
|
||||
var ret = await ReadAddrByte(endPoint, taskID, devAddr, timeout);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
if (!ret.Value.IsSuccessful)
|
||||
return new(new Exception($"Read device {address} address {devAddr} failed"));
|
||||
@@ -323,7 +344,7 @@ public class UDPClientPool
|
||||
await Task.Delay(waittime);
|
||||
try
|
||||
{
|
||||
var ret = await ReadAddr(endPoint, taskID, devAddr, Convert.ToInt32(timeleft.TotalMilliseconds));
|
||||
var ret = await ReadAddrByte(endPoint, taskID, devAddr, Convert.ToInt32(timeleft.TotalMilliseconds));
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
if (!ret.Value.IsSuccessful)
|
||||
return new(new Exception($"Read device {address} address {devAddr} failed"));
|
||||
@@ -465,7 +486,8 @@ public class UDPClientPool
|
||||
CommandID = Convert.ToByte(taskID),
|
||||
IsWrite = false,
|
||||
BurstLength = (byte)(currentSegmentSize - 1),
|
||||
Address = devAddr + (uint)(i * max4BytesPerRead)
|
||||
Address = (burstType == BurstType.ExtendBurst) ? (devAddr + (uint)(i * max4BytesPerRead)) : (devAddr),
|
||||
// Address = devAddr + (uint)(i * max4BytesPerRead),
|
||||
};
|
||||
pkgList.Add(new SendAddrPackage(opts));
|
||||
}
|
||||
@@ -553,7 +575,7 @@ public class UDPClientPool
|
||||
var resultData = new List<byte>();
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var ret = await ReadAddr(endPoint, taskID, addr[i], timeout);
|
||||
var ret = await ReadAddrByte(endPoint, taskID, addr[i], timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"ReadAddrSeq failed at index {i}: {ret.Error}");
|
||||
@@ -585,7 +607,8 @@ public class UDPClientPool
|
||||
/// <param name="timeout">超时时间(毫秒)</param>
|
||||
/// <returns>写入结果,true表示写入成功</returns>
|
||||
public static async ValueTask<Result<bool>> WriteAddr(
|
||||
IPEndPoint endPoint, int taskID, UInt32 devAddr, UInt32 data, int timeout = 1000)
|
||||
IPEndPoint endPoint, int taskID, UInt32 devAddr,
|
||||
UInt32 data, int timeout = 1000, ProgressReporter? progress = null)
|
||||
{
|
||||
var ret = false;
|
||||
var opts = new SendAddrPackOptions()
|
||||
@@ -596,14 +619,17 @@ public class UDPClientPool
|
||||
Address = devAddr,
|
||||
IsWrite = true,
|
||||
};
|
||||
progress?.Report(20);
|
||||
|
||||
// Write Register
|
||||
ret = await UDPClientPool.SendAddrPackAsync(endPoint, new SendAddrPackage(opts));
|
||||
if (!ret) return new(new Exception("Send 1st address package failed!"));
|
||||
progress?.Report(40);
|
||||
// Send Data Package
|
||||
ret = await UDPClientPool.SendDataPackAsync(endPoint,
|
||||
new SendDataPackage(Common.Number.NumberToBytes(data, 4).Value));
|
||||
if (!ret) return new(new Exception("Send data package failed!"));
|
||||
progress?.Report(60);
|
||||
|
||||
// Check Msg Bus
|
||||
if (!MsgBus.IsRunning)
|
||||
@@ -613,6 +639,7 @@ public class UDPClientPool
|
||||
var udpWriteAck = await MsgBus.UDPServer.WaitForAckAsync(
|
||||
endPoint.Address.ToString(), taskID, endPoint.Port, timeout);
|
||||
if (!udpWriteAck.IsSuccessful) return new(udpWriteAck.Error);
|
||||
progress?.Finish();
|
||||
|
||||
return udpWriteAck.Value.IsSuccessful;
|
||||
}
|
||||
@@ -627,7 +654,8 @@ public class UDPClientPool
|
||||
/// <param name="timeout">超时时间(毫秒)</param>
|
||||
/// <returns>写入结果,true表示写入成功</returns>
|
||||
public static async ValueTask<Result<bool>> WriteAddr(
|
||||
IPEndPoint endPoint, int taskID, UInt32 devAddr, byte[] dataArray, int timeout = 1000)
|
||||
IPEndPoint endPoint, int taskID, UInt32 devAddr,
|
||||
byte[] dataArray, int timeout = 1000, ProgressReporter? progress = null)
|
||||
{
|
||||
var ret = false;
|
||||
var opts = new SendAddrPackOptions()
|
||||
@@ -649,6 +677,8 @@ public class UDPClientPool
|
||||
var writeTimes = hasRest ?
|
||||
dataArray.Length / (max4BytesPerRead * (32 / 8)) + 1 :
|
||||
dataArray.Length / (max4BytesPerRead * (32 / 8));
|
||||
if (progress != null)
|
||||
progress.ExpectedSteps = writeTimes;
|
||||
for (var i = 0; i < writeTimes; i++)
|
||||
{
|
||||
// Sperate Data Array
|
||||
@@ -677,8 +707,11 @@ public class UDPClientPool
|
||||
|
||||
if (!udpWriteAck.Value.IsSuccessful)
|
||||
return false;
|
||||
|
||||
progress?.Increase();
|
||||
}
|
||||
|
||||
progress?.Finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
773
src/APIClient.ts
773
src/APIClient.ts
@@ -185,12 +185,8 @@ export class VideoStreamClient {
|
||||
return Promise.resolve<any>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 HTTP 视频流信息
|
||||
* @return 流信息
|
||||
*/
|
||||
getStreamInfo( cancelToken?: CancelToken): Promise<StreamInfoResult> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/StreamInfo";
|
||||
myEndpoint( cancelToken?: CancelToken): Promise<any> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/MyEndpoint";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
@@ -209,208 +205,11 @@ export class VideoStreamClient {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processGetStreamInfo(_response);
|
||||
return this.processMyEndpoint(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetStreamInfo(response: AxiosResponse): Promise<StreamInfoResult> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200) {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
result200 = StreamInfoResult.fromJS(resultData200);
|
||||
return Promise.resolve<StreamInfoResult>(result200);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
let result500: any = null;
|
||||
let resultData500 = _responseText;
|
||||
result500 = Exception.fromJS(resultData500);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<StreamInfoResult>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置摄像头连接参数
|
||||
* @param config 摄像头配置
|
||||
* @return 配置结果
|
||||
*/
|
||||
configureCamera(config: CameraConfigRequest, cancelToken?: CancelToken): Promise<any> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/ConfigureCamera";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
const content_ = JSON.stringify(config);
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
data: content_,
|
||||
method: "POST",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processConfigureCamera(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processConfigureCamera(response: AxiosResponse): Promise<any> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200) {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return Promise.resolve<any>(result200);
|
||||
|
||||
} else if (status === 400) {
|
||||
const _responseText = response.data;
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText;
|
||||
result400 = resultData400 !== undefined ? resultData400 : <any>null;
|
||||
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
let result500: any = null;
|
||||
let resultData500 = _responseText;
|
||||
result500 = Exception.fromJS(resultData500);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<any>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前摄像头配置
|
||||
* @return 摄像头配置信息
|
||||
*/
|
||||
getCameraConfig( cancelToken?: CancelToken): Promise<any> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/CameraConfig";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
method: "GET",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processGetCameraConfig(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetCameraConfig(response: AxiosResponse): Promise<any> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200) {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return Promise.resolve<any>(result200);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
let result500: any = null;
|
||||
let resultData500 = _responseText;
|
||||
result500 = Exception.fromJS(resultData500);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<any>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 控制 HTTP 视频流服务开关
|
||||
* @param enabled (optional) 是否启用服务
|
||||
* @return 操作结果
|
||||
*/
|
||||
setEnabled(enabled: boolean | undefined, cancelToken?: CancelToken): Promise<any> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/SetEnabled?";
|
||||
if (enabled === null)
|
||||
throw new Error("The parameter 'enabled' cannot be null.");
|
||||
else if (enabled !== undefined)
|
||||
url_ += "enabled=" + encodeURIComponent("" + enabled) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
method: "POST",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processSetEnabled(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processSetEnabled(response: AxiosResponse): Promise<any> {
|
||||
protected processMyEndpoint(response: AxiosResponse): Promise<any> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
@@ -502,6 +301,59 @@ export class VideoStreamClient {
|
||||
return Promise.resolve<boolean>(null as any);
|
||||
}
|
||||
|
||||
disableHdmiTransmission( cancelToken?: CancelToken): Promise<FileResponse | null> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/DisableTransmission";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
responseType: "blob",
|
||||
method: "POST",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/octet-stream"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processDisableHdmiTransmission(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processDisableHdmiTransmission(response: AxiosResponse): Promise<FileResponse | null> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200 || status === 206) {
|
||||
const contentDisposition = response.headers ? response.headers["content-disposition"] : undefined;
|
||||
let fileNameMatch = contentDisposition ? /filename\*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/g.exec(contentDisposition) : undefined;
|
||||
let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;
|
||||
if (fileName) {
|
||||
fileName = decodeURIComponent(fileName);
|
||||
} else {
|
||||
fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
|
||||
fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
|
||||
}
|
||||
return Promise.resolve({ fileName: fileName, status: status, data: new Blob([response.data], { type: response.headers["content-type"] }), headers: _headers });
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<FileResponse | null>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置视频流分辨率
|
||||
* @param request 分辨率配置请求
|
||||
@@ -576,67 +428,6 @@ export class VideoStreamClient {
|
||||
return Promise.resolve<any>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前分辨率
|
||||
* @return 当前分辨率信息
|
||||
*/
|
||||
getCurrentResolution( cancelToken?: CancelToken): Promise<any> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/Resolution";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
method: "GET",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processGetCurrentResolution(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetCurrentResolution(response: AxiosResponse): Promise<any> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200) {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return Promise.resolve<any>(result200);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
let result500: any = null;
|
||||
let resultData500 = _responseText;
|
||||
result500 = resultData500 !== undefined ? resultData500 : <any>null;
|
||||
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<any>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支持的分辨率列表
|
||||
* @return 支持的分辨率列表
|
||||
@@ -835,75 +626,6 @@ export class VideoStreamClient {
|
||||
}
|
||||
return Promise.resolve<any>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行一次自动对焦 (GET方式)
|
||||
* @return 对焦结果
|
||||
*/
|
||||
focus( cancelToken?: CancelToken): Promise<any> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/Focus";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
method: "GET",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processFocus(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processFocus(response: AxiosResponse): Promise<any> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200) {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return Promise.resolve<any>(result200);
|
||||
|
||||
} else if (status === 400) {
|
||||
const _responseText = response.data;
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText;
|
||||
result400 = resultData400 !== undefined ? resultData400 : <any>null;
|
||||
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
let result500: any = null;
|
||||
let resultData500 = _responseText;
|
||||
result500 = resultData500 !== undefined ? resultData500 : <any>null;
|
||||
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<any>(null as any);
|
||||
}
|
||||
}
|
||||
|
||||
export class BsdlParserClient {
|
||||
@@ -2944,6 +2666,176 @@ export class ExamClient {
|
||||
}
|
||||
}
|
||||
|
||||
export class HdmiVideoStreamClient {
|
||||
protected instance: AxiosInstance;
|
||||
protected baseUrl: string;
|
||||
protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;
|
||||
|
||||
constructor(baseUrl?: string, instance?: AxiosInstance) {
|
||||
|
||||
this.instance = instance || axios.create();
|
||||
|
||||
this.baseUrl = baseUrl ?? "http://127.0.0.1:5000";
|
||||
|
||||
}
|
||||
|
||||
getAllEndpoints( cancelToken?: CancelToken): Promise<HdmiVideoStreamEndpoint[]> {
|
||||
let url_ = this.baseUrl + "/api/HdmiVideoStream/AllEndpoints";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
method: "GET",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processGetAllEndpoints(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetAllEndpoints(response: AxiosResponse): Promise<HdmiVideoStreamEndpoint[]> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200) {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
if (Array.isArray(resultData200)) {
|
||||
result200 = [] as any;
|
||||
for (let item of resultData200)
|
||||
result200!.push(HdmiVideoStreamEndpoint.fromJS(item));
|
||||
}
|
||||
else {
|
||||
result200 = <any>null;
|
||||
}
|
||||
return Promise.resolve<HdmiVideoStreamEndpoint[]>(result200);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<HdmiVideoStreamEndpoint[]>(null as any);
|
||||
}
|
||||
|
||||
getMyEndpoint( cancelToken?: CancelToken): Promise<HdmiVideoStreamEndpoint> {
|
||||
let url_ = this.baseUrl + "/api/HdmiVideoStream/MyEndpoint";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
method: "GET",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processGetMyEndpoint(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetMyEndpoint(response: AxiosResponse): Promise<HdmiVideoStreamEndpoint> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200) {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
result200 = HdmiVideoStreamEndpoint.fromJS(resultData200);
|
||||
return Promise.resolve<HdmiVideoStreamEndpoint>(result200);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<HdmiVideoStreamEndpoint>(null as any);
|
||||
}
|
||||
|
||||
disableHdmiTransmission( cancelToken?: CancelToken): Promise<FileResponse | null> {
|
||||
let url_ = this.baseUrl + "/api/HdmiVideoStream/DisableHdmiTransmission";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
responseType: "blob",
|
||||
method: "POST",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/octet-stream"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processDisableHdmiTransmission(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processDisableHdmiTransmission(response: AxiosResponse): Promise<FileResponse | null> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200 || status === 206) {
|
||||
const contentDisposition = response.headers ? response.headers["content-disposition"] : undefined;
|
||||
let fileNameMatch = contentDisposition ? /filename\*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/g.exec(contentDisposition) : undefined;
|
||||
let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;
|
||||
if (fileName) {
|
||||
fileName = decodeURIComponent(fileName);
|
||||
} else {
|
||||
fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
|
||||
fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
|
||||
}
|
||||
return Promise.resolve({ fileName: fileName, status: status, data: new Blob([response.data], { type: response.headers["content-type"] }), headers: _headers });
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<FileResponse | null>(null as any);
|
||||
}
|
||||
}
|
||||
|
||||
export class JtagClient {
|
||||
protected instance: AxiosInstance;
|
||||
protected baseUrl: string;
|
||||
@@ -3161,9 +3053,9 @@ export class JtagClient {
|
||||
* @param address (optional) JTAG 设备地址
|
||||
* @param port (optional) JTAG 设备端口
|
||||
* @param bitstreamId (optional) 比特流ID
|
||||
* @return 下载结果
|
||||
* @return 进度跟踪TaskID
|
||||
*/
|
||||
downloadBitstream(address: string | undefined, port: number | undefined, bitstreamId: number | undefined, cancelToken?: CancelToken): Promise<boolean> {
|
||||
downloadBitstream(address: string | undefined, port: number | undefined, bitstreamId: number | undefined, cancelToken?: CancelToken): Promise<string> {
|
||||
let url_ = this.baseUrl + "/api/Jtag/DownloadBitstream?";
|
||||
if (address === null)
|
||||
throw new Error("The parameter 'address' cannot be null.");
|
||||
@@ -3199,7 +3091,7 @@ export class JtagClient {
|
||||
});
|
||||
}
|
||||
|
||||
protected processDownloadBitstream(response: AxiosResponse): Promise<boolean> {
|
||||
protected processDownloadBitstream(response: AxiosResponse): Promise<string> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
@@ -3215,7 +3107,7 @@ export class JtagClient {
|
||||
let resultData200 = _responseText;
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return Promise.resolve<boolean>(result200);
|
||||
return Promise.resolve<string>(result200);
|
||||
|
||||
} else if (status === 400) {
|
||||
const _responseText = response.data;
|
||||
@@ -3243,7 +3135,7 @@ export class JtagClient {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<boolean>(null as any);
|
||||
return Promise.resolve<string>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3831,9 +3723,10 @@ export class LogicAnalyzerClient {
|
||||
* @param capture_length (optional) 深度
|
||||
* @param pre_capture_length (optional) 预采样深度
|
||||
* @param channel_div (optional) 有效通道(0-[1],1-[2],2-[4],3-[8],4-[16],5-[32])
|
||||
* @param clock_div (optional) 采样时钟分频系数
|
||||
* @return 操作结果
|
||||
*/
|
||||
setCaptureParams(capture_length: number | undefined, pre_capture_length: number | undefined, channel_div: AnalyzerChannelDiv | undefined, cancelToken?: CancelToken): Promise<boolean> {
|
||||
setCaptureParams(capture_length: number | undefined, pre_capture_length: number | undefined, channel_div: AnalyzerChannelDiv | undefined, clock_div: AnalyzerClockDiv | undefined, cancelToken?: CancelToken): Promise<boolean> {
|
||||
let url_ = this.baseUrl + "/api/LogicAnalyzer/SetCaptureParams?";
|
||||
if (capture_length === null)
|
||||
throw new Error("The parameter 'capture_length' cannot be null.");
|
||||
@@ -3847,6 +3740,10 @@ export class LogicAnalyzerClient {
|
||||
throw new Error("The parameter 'channel_div' cannot be null.");
|
||||
else if (channel_div !== undefined)
|
||||
url_ += "channel_div=" + encodeURIComponent("" + channel_div) + "&";
|
||||
if (clock_div === null)
|
||||
throw new Error("The parameter 'clock_div' cannot be null.");
|
||||
else if (clock_div !== undefined)
|
||||
url_ += "clock_div=" + encodeURIComponent("" + clock_div) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
@@ -7078,134 +6975,6 @@ export interface IException {
|
||||
stackTrace?: string | undefined;
|
||||
}
|
||||
|
||||
/** 视频流信息结构体 */
|
||||
export class StreamInfoResult implements IStreamInfoResult {
|
||||
/** TODO: */
|
||||
frameRate!: number;
|
||||
/** TODO: */
|
||||
frameWidth!: number;
|
||||
/** TODO: */
|
||||
frameHeight!: number;
|
||||
/** TODO: */
|
||||
format!: string;
|
||||
/** TODO: */
|
||||
htmlUrl!: string;
|
||||
/** TODO: */
|
||||
mjpegUrl!: string;
|
||||
/** TODO: */
|
||||
snapshotUrl!: string;
|
||||
/** TODO: */
|
||||
usbCameraUrl!: string;
|
||||
|
||||
constructor(data?: IStreamInfoResult) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
(<any>this)[property] = (<any>data)[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.frameRate = _data["frameRate"];
|
||||
this.frameWidth = _data["frameWidth"];
|
||||
this.frameHeight = _data["frameHeight"];
|
||||
this.format = _data["format"];
|
||||
this.htmlUrl = _data["htmlUrl"];
|
||||
this.mjpegUrl = _data["mjpegUrl"];
|
||||
this.snapshotUrl = _data["snapshotUrl"];
|
||||
this.usbCameraUrl = _data["usbCameraUrl"];
|
||||
}
|
||||
}
|
||||
|
||||
static fromJS(data: any): StreamInfoResult {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
let result = new StreamInfoResult();
|
||||
result.init(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["frameRate"] = this.frameRate;
|
||||
data["frameWidth"] = this.frameWidth;
|
||||
data["frameHeight"] = this.frameHeight;
|
||||
data["format"] = this.format;
|
||||
data["htmlUrl"] = this.htmlUrl;
|
||||
data["mjpegUrl"] = this.mjpegUrl;
|
||||
data["snapshotUrl"] = this.snapshotUrl;
|
||||
data["usbCameraUrl"] = this.usbCameraUrl;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/** 视频流信息结构体 */
|
||||
export interface IStreamInfoResult {
|
||||
/** TODO: */
|
||||
frameRate: number;
|
||||
/** TODO: */
|
||||
frameWidth: number;
|
||||
/** TODO: */
|
||||
frameHeight: number;
|
||||
/** TODO: */
|
||||
format: string;
|
||||
/** TODO: */
|
||||
htmlUrl: string;
|
||||
/** TODO: */
|
||||
mjpegUrl: string;
|
||||
/** TODO: */
|
||||
snapshotUrl: string;
|
||||
/** TODO: */
|
||||
usbCameraUrl: string;
|
||||
}
|
||||
|
||||
/** 摄像头配置请求模型 */
|
||||
export class CameraConfigRequest implements ICameraConfigRequest {
|
||||
/** 摄像头地址 */
|
||||
address!: string;
|
||||
/** 摄像头端口 */
|
||||
port!: number;
|
||||
|
||||
constructor(data?: ICameraConfigRequest) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
(<any>this)[property] = (<any>data)[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.address = _data["address"];
|
||||
this.port = _data["port"];
|
||||
}
|
||||
}
|
||||
|
||||
static fromJS(data: any): CameraConfigRequest {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
let result = new CameraConfigRequest();
|
||||
result.init(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["address"] = this.address;
|
||||
data["port"] = this.port;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/** 摄像头配置请求模型 */
|
||||
export interface ICameraConfigRequest {
|
||||
/** 摄像头地址 */
|
||||
address: string;
|
||||
/** 摄像头端口 */
|
||||
port: number;
|
||||
}
|
||||
|
||||
/** 分辨率配置请求模型 */
|
||||
export class ResolutionConfigRequest implements IResolutionConfigRequest {
|
||||
/** 宽度 */
|
||||
@@ -8019,6 +7788,54 @@ export interface ICreateExamRequest {
|
||||
isVisibleToUsers: boolean;
|
||||
}
|
||||
|
||||
export class HdmiVideoStreamEndpoint implements IHdmiVideoStreamEndpoint {
|
||||
boardId!: string;
|
||||
mjpegUrl!: string;
|
||||
videoUrl!: string;
|
||||
snapshotUrl!: string;
|
||||
|
||||
constructor(data?: IHdmiVideoStreamEndpoint) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
(<any>this)[property] = (<any>data)[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.boardId = _data["boardId"];
|
||||
this.mjpegUrl = _data["mjpegUrl"];
|
||||
this.videoUrl = _data["videoUrl"];
|
||||
this.snapshotUrl = _data["snapshotUrl"];
|
||||
}
|
||||
}
|
||||
|
||||
static fromJS(data: any): HdmiVideoStreamEndpoint {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
let result = new HdmiVideoStreamEndpoint();
|
||||
result.init(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["boardId"] = this.boardId;
|
||||
data["mjpegUrl"] = this.mjpegUrl;
|
||||
data["videoUrl"] = this.videoUrl;
|
||||
data["snapshotUrl"] = this.snapshotUrl;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IHdmiVideoStreamEndpoint {
|
||||
boardId: string;
|
||||
mjpegUrl: string;
|
||||
videoUrl: string;
|
||||
snapshotUrl: string;
|
||||
}
|
||||
|
||||
/** 逻辑分析仪运行状态枚举 */
|
||||
export enum CaptureStatus {
|
||||
None = 0,
|
||||
@@ -8068,6 +7885,18 @@ export enum AnalyzerChannelDiv {
|
||||
XXXII = 5,
|
||||
}
|
||||
|
||||
/** 逻辑分析仪采样时钟分频系数 */
|
||||
export enum AnalyzerClockDiv {
|
||||
DIV1 = 0,
|
||||
DIV2 = 1,
|
||||
DIV4 = 2,
|
||||
DIV8 = 3,
|
||||
DIV16 = 4,
|
||||
DIV32 = 5,
|
||||
DIV64 = 6,
|
||||
DIV128 = 7,
|
||||
}
|
||||
|
||||
/** 捕获配置 */
|
||||
export class CaptureConfig implements ICaptureConfig {
|
||||
/** 全局触发模式 */
|
||||
@@ -8078,6 +7907,8 @@ export class CaptureConfig implements ICaptureConfig {
|
||||
preCaptureLength!: number;
|
||||
/** 有效通道 */
|
||||
channelDiv!: AnalyzerChannelDiv;
|
||||
/** 时钟分频系数 */
|
||||
clockDiv!: AnalyzerClockDiv;
|
||||
/** 信号触发配置列表 */
|
||||
signalConfigs!: SignalTriggerConfig[];
|
||||
|
||||
@@ -8099,6 +7930,7 @@ export class CaptureConfig implements ICaptureConfig {
|
||||
this.captureLength = _data["captureLength"];
|
||||
this.preCaptureLength = _data["preCaptureLength"];
|
||||
this.channelDiv = _data["channelDiv"];
|
||||
this.clockDiv = _data["clockDiv"];
|
||||
if (Array.isArray(_data["signalConfigs"])) {
|
||||
this.signalConfigs = [] as any;
|
||||
for (let item of _data["signalConfigs"])
|
||||
@@ -8120,6 +7952,7 @@ export class CaptureConfig implements ICaptureConfig {
|
||||
data["captureLength"] = this.captureLength;
|
||||
data["preCaptureLength"] = this.preCaptureLength;
|
||||
data["channelDiv"] = this.channelDiv;
|
||||
data["clockDiv"] = this.clockDiv;
|
||||
if (Array.isArray(this.signalConfigs)) {
|
||||
data["signalConfigs"] = [];
|
||||
for (let item of this.signalConfigs)
|
||||
@@ -8139,6 +7972,8 @@ export interface ICaptureConfig {
|
||||
preCaptureLength: number;
|
||||
/** 有效通道 */
|
||||
channelDiv: AnalyzerChannelDiv;
|
||||
/** 时钟分频系数 */
|
||||
clockDiv: AnalyzerClockDiv;
|
||||
/** 信号触发配置列表 */
|
||||
signalConfigs: SignalTriggerConfig[];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
/* tslint:disable */
|
||||
// @ts-nocheck
|
||||
import type { HubConnection, IStreamResult, Subject } from '@microsoft/signalr';
|
||||
import type { IJtagHub, IJtagReceiver } from './server.Hubs.JtagHub';
|
||||
import type { IJtagHub, IProgressHub, IJtagReceiver, IProgressReceiver } from './server.Hubs';
|
||||
import type { ProgressInfo } from '../server.Hubs';
|
||||
|
||||
|
||||
// components
|
||||
@@ -43,22 +44,30 @@ class ReceiverMethodSubscription implements Disposable {
|
||||
|
||||
export type HubProxyFactoryProvider = {
|
||||
(hubType: "IJtagHub"): HubProxyFactory<IJtagHub>;
|
||||
(hubType: "IProgressHub"): HubProxyFactory<IProgressHub>;
|
||||
}
|
||||
|
||||
export const getHubProxyFactory = ((hubType: string) => {
|
||||
if(hubType === "IJtagHub") {
|
||||
return IJtagHub_HubProxyFactory.Instance;
|
||||
}
|
||||
if(hubType === "IProgressHub") {
|
||||
return IProgressHub_HubProxyFactory.Instance;
|
||||
}
|
||||
}) as HubProxyFactoryProvider;
|
||||
|
||||
export type ReceiverRegisterProvider = {
|
||||
(receiverType: "IJtagReceiver"): ReceiverRegister<IJtagReceiver>;
|
||||
(receiverType: "IProgressReceiver"): ReceiverRegister<IProgressReceiver>;
|
||||
}
|
||||
|
||||
export const getReceiverRegister = ((receiverType: string) => {
|
||||
if(receiverType === "IJtagReceiver") {
|
||||
return IJtagReceiver_Binder.Instance;
|
||||
}
|
||||
if(receiverType === "IProgressReceiver") {
|
||||
return IProgressReceiver_Binder.Instance;
|
||||
}
|
||||
}) as ReceiverRegisterProvider;
|
||||
|
||||
// HubProxy
|
||||
@@ -92,6 +101,27 @@ class IJtagHub_HubProxy implements IJtagHub {
|
||||
}
|
||||
}
|
||||
|
||||
class IProgressHub_HubProxyFactory implements HubProxyFactory<IProgressHub> {
|
||||
public static Instance = new IProgressHub_HubProxyFactory();
|
||||
|
||||
private constructor() {
|
||||
}
|
||||
|
||||
public readonly createHubProxy = (connection: HubConnection): IProgressHub => {
|
||||
return new IProgressHub_HubProxy(connection);
|
||||
}
|
||||
}
|
||||
|
||||
class IProgressHub_HubProxy implements IProgressHub {
|
||||
|
||||
public constructor(private connection: HubConnection) {
|
||||
}
|
||||
|
||||
public readonly join = async (taskId: string): Promise<boolean> => {
|
||||
return await this.connection.invoke("Join", taskId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Receiver
|
||||
|
||||
@@ -116,3 +146,24 @@ class IJtagReceiver_Binder implements ReceiverRegister<IJtagReceiver> {
|
||||
}
|
||||
}
|
||||
|
||||
class IProgressReceiver_Binder implements ReceiverRegister<IProgressReceiver> {
|
||||
|
||||
public static Instance = new IProgressReceiver_Binder();
|
||||
|
||||
private constructor() {
|
||||
}
|
||||
|
||||
public readonly register = (connection: HubConnection, receiver: IProgressReceiver): Disposable => {
|
||||
|
||||
const __onReceiveProgress = (...args: [ProgressInfo]) => receiver.onReceiveProgress(...args);
|
||||
|
||||
connection.on("OnReceiveProgress", __onReceiveProgress);
|
||||
|
||||
const methodList: ReceiverMethod[] = [
|
||||
{ methodName: "OnReceiveProgress", method: __onReceiveProgress }
|
||||
]
|
||||
|
||||
return new ReceiverMethodSubscription(connection, methodList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
/* tslint:disable */
|
||||
// @ts-nocheck
|
||||
import type { IStreamResult, Subject } from '@microsoft/signalr';
|
||||
import type { ProgressInfo } from '../server.Hubs';
|
||||
|
||||
export type IJtagHub = {
|
||||
/**
|
||||
@@ -21,6 +22,14 @@ export type IJtagHub = {
|
||||
stopBoundaryScan(): Promise<boolean>;
|
||||
}
|
||||
|
||||
export type IProgressHub = {
|
||||
/**
|
||||
* @param taskId Transpiled from string
|
||||
* @returns Transpiled from System.Threading.Tasks.Task<bool>
|
||||
*/
|
||||
join(taskId: string): Promise<boolean>;
|
||||
}
|
||||
|
||||
export type IJtagReceiver = {
|
||||
/**
|
||||
* @param msg Transpiled from System.Collections.Generic.Dictionary<string, bool>
|
||||
@@ -29,3 +38,11 @@ export type IJtagReceiver = {
|
||||
onReceiveBoundaryScanData(msg: Partial<Record<string, boolean>>): Promise<void>;
|
||||
}
|
||||
|
||||
export type IProgressReceiver = {
|
||||
/**
|
||||
* @param message Transpiled from server.Hubs.ProgressInfo
|
||||
* @returns Transpiled from System.Threading.Tasks.Task
|
||||
*/
|
||||
onReceiveProgress(message: ProgressInfo): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
SignalTriggerConfig,
|
||||
SignalValue,
|
||||
AnalyzerChannelDiv,
|
||||
AnalyzerClockDiv,
|
||||
} from "@/APIClient";
|
||||
import { AuthManager } from "@/utils/AuthManager";
|
||||
import { useAlertStore } from "@/components/Alert";
|
||||
@@ -30,16 +31,8 @@ export type Channel = {
|
||||
|
||||
// 全局模式选项
|
||||
const globalModes = [
|
||||
{
|
||||
value: GlobalCaptureMode.AND,
|
||||
label: "AND",
|
||||
description: "所有条件都满足时触发",
|
||||
},
|
||||
{
|
||||
value: GlobalCaptureMode.OR,
|
||||
label: "OR",
|
||||
description: "任一条件满足时触发",
|
||||
},
|
||||
{value: GlobalCaptureMode.AND,label: "AND",description: "所有条件都满足时触发",},
|
||||
{value: GlobalCaptureMode.OR,label: "OR",description: "任一条件满足时触发",},
|
||||
{ value: GlobalCaptureMode.NAND, label: "NAND", description: "AND的非" },
|
||||
{ value: GlobalCaptureMode.NOR, label: "NOR", description: "OR的非" },
|
||||
];
|
||||
@@ -76,28 +69,23 @@ const channelDivOptions = [
|
||||
{ value: 32, label: "32通道", description: "启用32个通道 (CH0-CH31)" },
|
||||
];
|
||||
|
||||
// 捕获深度选项
|
||||
const captureLengthOptions = [
|
||||
{ value: 256, label: "256" },
|
||||
{ value: 512, label: "512" },
|
||||
{ value: 1024, label: "1K" },
|
||||
{ value: 2048, label: "2K" },
|
||||
{ value: 4096, label: "4K" },
|
||||
{ value: 8192, label: "8K" },
|
||||
{ value: 16384, label: "16K" },
|
||||
{ value: 32768, label: "32K" },
|
||||
const ClockDivOptions = [
|
||||
{ value: AnalyzerClockDiv.DIV1, label: "120MHz", description: "采样频率120MHz" },
|
||||
{ value: AnalyzerClockDiv.DIV2, label: "60MHz", description: "采样频率60MHz" },
|
||||
{ value: AnalyzerClockDiv.DIV4, label: "30MHz", description: "采样频率30MHz" },
|
||||
{ value: AnalyzerClockDiv.DIV8, label: "15MHz", description: "采样频率15MHz" },
|
||||
{ value: AnalyzerClockDiv.DIV16, label: "7.5MHz", description: "采样频率7.5MHz" },
|
||||
{ value: AnalyzerClockDiv.DIV32, label: "3.75MHz", description: "采样频率3.75MHz" },
|
||||
{ value: AnalyzerClockDiv.DIV64, label: "1.875MHz", description: "采样频率1.875MHz" },
|
||||
{ value: AnalyzerClockDiv.DIV128, label: "937.5KHz", description: "采样频率937.5KHz" },
|
||||
];
|
||||
|
||||
// 预捕获深度选项
|
||||
const preCaptureLengthOptions = [
|
||||
{ value: 0, label: "0" },
|
||||
{ value: 16, label: "16" },
|
||||
{ value: 32, label: "32" },
|
||||
{ value: 64, label: "64" },
|
||||
{ value: 128, label: "128" },
|
||||
{ value: 256, label: "256" },
|
||||
{ value: 512, label: "512" },
|
||||
];
|
||||
// 捕获深度限制常量
|
||||
const CAPTURE_LENGTH_MIN = 1024; // 最小捕获深度 1024
|
||||
const CAPTURE_LENGTH_MAX = 0x10000000 - 0x01000000; // 最大捕获深度
|
||||
|
||||
// 预捕获深度限制常量
|
||||
const PRE_CAPTURE_LENGTH_MIN = 2; // 最小预捕获深度 2
|
||||
|
||||
// 默认颜色数组
|
||||
const defaultColors = [
|
||||
@@ -111,9 +99,8 @@ const defaultColors = [
|
||||
"#8C33FF",
|
||||
];
|
||||
|
||||
// 添加逻辑分析仪频率常量
|
||||
const LOGIC_ANALYZER_FREQUENCY = 125_000_000; // 125MHz
|
||||
const SAMPLE_PERIOD_NS = 1_000_000_000 / LOGIC_ANALYZER_FREQUENCY; // 采样周期,单位:纳秒
|
||||
// 添加逻辑分析仪基础频率常量
|
||||
const BASE_LOGIC_ANALYZER_FREQUENCY = 120_000_000; // 120MHz基础频率
|
||||
|
||||
const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
||||
() => {
|
||||
@@ -126,8 +113,9 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
||||
// 触发设置相关状态
|
||||
const currentGlobalMode = ref<GlobalCaptureMode>(GlobalCaptureMode.AND);
|
||||
const currentChannelDiv = ref<number>(8); // 默认启用8个通道
|
||||
const captureLength = ref<number>(1024); // 捕获深度,默认1024
|
||||
const preCaptureLength = ref<number>(0); // 预捕获深度,默认0
|
||||
const captureLength = ref<number>(CAPTURE_LENGTH_MIN); // 捕获深度,默认为最小值
|
||||
const preCaptureLength = ref<number>(PRE_CAPTURE_LENGTH_MIN); // 预捕获深度,默认0
|
||||
const currentclockDiv = ref<AnalyzerClockDiv>(AnalyzerClockDiv.DIV1); // 默认时钟分频为1
|
||||
const isApplying = ref(false);
|
||||
const isCapturing = ref(false); // 添加捕获状态标识
|
||||
|
||||
@@ -168,6 +156,17 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
||||
channels.filter((channel) => channel.enabled),
|
||||
);
|
||||
|
||||
// 计算属性:根据当前时钟分频获取实际采样频率
|
||||
const currentSampleFrequency = computed(() => {
|
||||
const divValue = Math.pow(2, currentclockDiv.value);
|
||||
return BASE_LOGIC_ANALYZER_FREQUENCY / divValue;
|
||||
});
|
||||
|
||||
// 计算属性:获取当前采样周期(纳秒)
|
||||
const currentSamplePeriodNs = computed(() => {
|
||||
return 1_000_000_000 / currentSampleFrequency.value;
|
||||
});
|
||||
|
||||
// 转换通道数字到枚举值
|
||||
const getChannelDivEnum = (channelCount: number): AnalyzerChannelDiv => {
|
||||
switch (channelCount) {
|
||||
@@ -181,6 +180,64 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
||||
}
|
||||
};
|
||||
|
||||
// 验证捕获深度
|
||||
const validateCaptureLength = (value: number): { valid: boolean; message?: string } => {
|
||||
if (!Number.isInteger(value)) {
|
||||
return { valid: false, message: "捕获深度必须是整数" };
|
||||
}
|
||||
if (value < CAPTURE_LENGTH_MIN) {
|
||||
return { valid: false, message: `捕获深度不能小于 ${CAPTURE_LENGTH_MIN}` };
|
||||
}
|
||||
if (value > CAPTURE_LENGTH_MAX) {
|
||||
return { valid: false, message: `捕获深度不能大于 ${CAPTURE_LENGTH_MAX.toLocaleString()}` };
|
||||
}
|
||||
return { valid: true };
|
||||
};
|
||||
|
||||
// 验证预捕获深度
|
||||
const validatePreCaptureLength = (value: number, currentCaptureLength: number): { valid: boolean; message?: string } => {
|
||||
if (!Number.isInteger(value)) {
|
||||
return { valid: false, message: "预捕获深度必须是整数" };
|
||||
}
|
||||
if (value < PRE_CAPTURE_LENGTH_MIN) {
|
||||
return { valid: false, message: `预捕获深度不能小于 ${PRE_CAPTURE_LENGTH_MIN}` };
|
||||
}
|
||||
if (value >= currentCaptureLength) {
|
||||
return { valid: false, message: `预捕获深度不能大于等于捕获深度 (${currentCaptureLength})` };
|
||||
}
|
||||
return { valid: true };
|
||||
};
|
||||
|
||||
// 设置捕获深度
|
||||
const setCaptureLength = (value: number) => {
|
||||
const validation = validateCaptureLength(value);
|
||||
if (!validation.valid) {
|
||||
alert?.error(validation.message!, 3000);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查预捕获深度是否仍然有效
|
||||
if (preCaptureLength.value >= value) {
|
||||
preCaptureLength.value = Math.max(0, value - 1);
|
||||
alert?.warn(`预捕获深度已自动调整为 ${preCaptureLength.value}`, 3000);
|
||||
}
|
||||
|
||||
captureLength.value = value;
|
||||
return true;
|
||||
};
|
||||
|
||||
// 设置预捕获深度
|
||||
const setPreCaptureLength = (value: number) => {
|
||||
const validation = validatePreCaptureLength(value, captureLength.value);
|
||||
if (!validation.valid) {
|
||||
alert?.error(validation.message!, 3000);
|
||||
return false;
|
||||
}
|
||||
|
||||
preCaptureLength.value = value;
|
||||
return true;
|
||||
};
|
||||
|
||||
// 设置通道组
|
||||
const setChannelDiv = (channelCount: number) => {
|
||||
// 验证通道数量是否有效
|
||||
@@ -210,9 +267,16 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
||||
alert?.info(`全局触发模式已设置为 ${modeOption?.label}`, 2000);
|
||||
};
|
||||
|
||||
const setClockDiv = (mode: AnalyzerClockDiv) => {
|
||||
currentclockDiv.value = mode;
|
||||
const modeOption = ClockDivOptions.find((m) => m.value === mode);
|
||||
alert?.info(`时钟分频已设置为 ${modeOption?.label}`, 2000);
|
||||
};
|
||||
|
||||
const resetConfiguration = () => {
|
||||
currentGlobalMode.value = GlobalCaptureMode.AND;
|
||||
currentChannelDiv.value = 8; // 重置为默认的8通道
|
||||
currentclockDiv.value = AnalyzerClockDiv.DIV1; // 重置为默认采样频率
|
||||
setChannelDiv(8); // 重置为默认的8通道
|
||||
|
||||
signalConfigs.forEach((signal) => {
|
||||
@@ -243,7 +307,7 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
||||
|
||||
// 根据当前通道数量解析数据
|
||||
const channelCount = currentChannelDiv.value;
|
||||
const timeStepNs = SAMPLE_PERIOD_NS;
|
||||
const timeStepNs = currentSamplePeriodNs.value;
|
||||
|
||||
let sampleCount: number;
|
||||
let x: number[];
|
||||
@@ -486,6 +550,7 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
||||
channelDiv: getChannelDivEnum(currentChannelDiv.value),
|
||||
captureLength: captureLength.value,
|
||||
preCaptureLength: preCaptureLength.value,
|
||||
clockDiv: currentclockDiv.value,
|
||||
signalConfigs: allSignals,
|
||||
});
|
||||
|
||||
@@ -624,13 +689,13 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
||||
|
||||
// 添加生成测试数据的方法
|
||||
const generateTestData = () => {
|
||||
const sampleRate = LOGIC_ANALYZER_FREQUENCY; // 使用实际的逻辑分析仪频率
|
||||
const sampleRate = currentSampleFrequency.value; // 使用当前设置的采样频率
|
||||
const duration = 0.001; // 1ms的数据
|
||||
const points = Math.floor(sampleRate * duration);
|
||||
|
||||
const x = Array.from(
|
||||
{ length: points },
|
||||
(_, i) => (i * SAMPLE_PERIOD_NS) / 1000, // 时间轴,单位:微秒
|
||||
(_, i) => (i * currentSamplePeriodNs.value) / 1000, // 时间轴,单位:微秒
|
||||
);
|
||||
|
||||
// Generate 8 channels with different digital patterns
|
||||
@@ -703,6 +768,7 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
||||
currentChannelDiv, // 导出当前通道组状态
|
||||
captureLength, // 导出捕获深度
|
||||
preCaptureLength, // 导出预捕获深度
|
||||
currentclockDiv, // 导出当前采样频率状态
|
||||
isApplying,
|
||||
isCapturing, // 导出捕获状态
|
||||
isOperationInProgress, // 导出操作进行状态
|
||||
@@ -711,18 +777,29 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
||||
enabledChannelCount,
|
||||
channelNames,
|
||||
enabledChannels,
|
||||
currentSampleFrequency, // 导出当前采样频率
|
||||
currentSamplePeriodNs, // 导出当前采样周期
|
||||
|
||||
// 选项数据
|
||||
globalModes,
|
||||
operators,
|
||||
signalValues,
|
||||
channelDivOptions, // 导出通道组选项
|
||||
captureLengthOptions, // 导出捕获深度选项
|
||||
preCaptureLengthOptions, // 导出预捕获深度选项
|
||||
ClockDivOptions, // 导出采样频率选项
|
||||
|
||||
// 捕获深度常量和验证
|
||||
CAPTURE_LENGTH_MIN,
|
||||
CAPTURE_LENGTH_MAX,
|
||||
PRE_CAPTURE_LENGTH_MIN,
|
||||
validateCaptureLength,
|
||||
validatePreCaptureLength,
|
||||
setCaptureLength,
|
||||
setPreCaptureLength,
|
||||
|
||||
// 触发设置方法
|
||||
setChannelDiv, // 导出设置通道组方法
|
||||
setGlobalMode,
|
||||
setClockDiv, // 导出设置采样频率方法
|
||||
resetConfiguration,
|
||||
setLogicData,
|
||||
startCapture,
|
||||
|
||||
@@ -3,89 +3,220 @@
|
||||
<!-- 通道配置 -->
|
||||
<div class="form-control">
|
||||
<!-- 全局触发模式选择和通道组配置 -->
|
||||
<div class="flex flex-col lg:flex-row justify-between gap-4 my-4 mx-2">
|
||||
<!-- 左侧:全局触发模式和通道组选择 -->
|
||||
<div class="flex flex-col lg:flex-row gap-4">
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
<label class="label">
|
||||
<span class="label-text text-sm">全局触发逻辑</span>
|
||||
<div class="flex flex-col gap-6 my-4 mx-2">
|
||||
<div class="flex flex-col lg:flex-row gap-6">
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="block text-sm font-semibold antialiased">
|
||||
全局触发逻辑
|
||||
</label>
|
||||
<select
|
||||
v-model="currentGlobalMode"
|
||||
@change="setGlobalMode(currentGlobalMode)"
|
||||
class="select select-sm select-bordered"
|
||||
>
|
||||
<option
|
||||
v-for="mode in globalModes"
|
||||
:key="mode.value"
|
||||
:value="mode.value"
|
||||
<div class="relative w-[200px]">
|
||||
<button
|
||||
tabindex="0"
|
||||
type="button"
|
||||
class="flex items-center gap-4 justify-between h-max outline-none focus:outline-none bg-transparent ring-transparent border border-slate-200 transition-all duration-300 ease-in disabled:opacity-50 disabled:pointer-events-none select-none text-start text-sm rounded-md py-2 px-2.5 ring shadow-sm hover:border-slate-800 hover:ring-slate-800/10 focus:border-slate-800 focus:ring-slate-800/10 w-full"
|
||||
@click="toggleGlobalModeDropdown"
|
||||
:aria-expanded="showGlobalModeDropdown"
|
||||
aria-haspopup="listbox"
|
||||
role="combobox"
|
||||
>
|
||||
{{ mode.label }} - {{ mode.description }}
|
||||
</option>
|
||||
</select>
|
||||
<span>{{ currentGlobalModeLabel }}</span>
|
||||
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="currentColor" class="h-[1em] w-[1em] translate-x-0.5 stroke-[1.5]">
|
||||
<path d="M17 8L12 3L7 8" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path>
|
||||
<path d="M17 16L12 21L7 16" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path>
|
||||
</svg>
|
||||
</button>
|
||||
<input readonly style="display:none" :value="currentGlobalMode" />
|
||||
<!-- 下拉菜单 -->
|
||||
<div v-if="showGlobalModeDropdown" class="absolute top-full left-0 right-0 mt-1 bg-white border border-slate-200 rounded-md shadow-lg z-50">
|
||||
<div
|
||||
v-for="mode in globalModes"
|
||||
:key="mode.value"
|
||||
@click="selectGlobalMode(mode.value)"
|
||||
class="px-3 py-2 text-sm text-slate-700 hover:bg-slate-100 cursor-pointer"
|
||||
:class="{ 'bg-slate-100': mode.value === currentGlobalMode }"
|
||||
>
|
||||
{{ mode.label }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="flex items-center text-xs text-slate-400">
|
||||
{{ currentGlobalModeDescription }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
<label class="label">
|
||||
<span class="label-text text-sm">通道组</span>
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="block text-sm font-semibold antialiased">
|
||||
通道组
|
||||
</label>
|
||||
<select
|
||||
v-model="currentChannelDiv"
|
||||
@change="setChannelDiv(currentChannelDiv)"
|
||||
class="select select-sm select-bordered"
|
||||
>
|
||||
<option
|
||||
v-for="option in channelDivOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
<div class="relative w-[200px]">
|
||||
<button
|
||||
tabindex="0"
|
||||
type="button"
|
||||
class="flex items-center gap-4 justify-between h-max outline-none focus:outline-none bg-transparent ring-transparent border border-slate-200 transition-all duration-300 ease-in disabled:opacity-50 disabled:pointer-events-none select-none text-start text-sm rounded-md py-2 px-2.5 ring shadow-sm hover:border-slate-800 hover:ring-slate-800/10 focus:border-slate-800 focus:ring-slate-800/10 w-full"
|
||||
@click="toggleChannelDivDropdown"
|
||||
:aria-expanded="showChannelDivDropdown"
|
||||
aria-haspopup="listbox"
|
||||
role="combobox"
|
||||
>
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
<span>{{ currentChannelDivLabel }}</span>
|
||||
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="currentColor" class="h-[1em] w-[1em] translate-x-0.5 stroke-[1.5]">
|
||||
<path d="M17 8L12 3L7 8" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path>
|
||||
<path d="M17 16L12 21L7 16" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path>
|
||||
</svg>
|
||||
</button>
|
||||
<input readonly style="display:none" :value="currentChannelDiv" />
|
||||
<!-- 下拉菜单 -->
|
||||
<div v-if="showChannelDivDropdown" class="absolute top-full left-0 right-0 mt-1 bg-white border border-slate-200 rounded-md shadow-lg z-50">
|
||||
<div
|
||||
v-for="option in channelDivOptions"
|
||||
:key="option.value"
|
||||
@click="selectChannelDiv(option.value)"
|
||||
class="px-3 py-2 text-sm text-slate-700 hover:bg-slate-100 cursor-pointer"
|
||||
:class="{ 'bg-slate-100': option.value === currentChannelDiv }"
|
||||
>
|
||||
{{ option.label }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="flex items-center text-xs text-slate-400">
|
||||
{{ currentChannelDivDescription }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
<label class="label">
|
||||
<span class="label-text text-sm">捕获深度</span>
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="block text-sm font-semibold antialiased text-slate-800">
|
||||
采样频率
|
||||
</label>
|
||||
<select
|
||||
v-model="captureLength"
|
||||
class="select select-sm select-bordered"
|
||||
>
|
||||
<option
|
||||
v-for="option in captureLengthOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
<div class="relative w-[200px]">
|
||||
<button
|
||||
tabindex="0"
|
||||
type="button"
|
||||
class="flex items-center gap-4 justify-between h-max outline-none focus:outline-none text-slate-600 bg-transparent ring-transparent border border-slate-200 transition-all duration-300 ease-in disabled:opacity-50 disabled:pointer-events-none select-none text-start text-sm rounded-md py-2 px-2.5 ring shadow-sm hover:border-slate-800 hover:ring-slate-800/10 focus:border-slate-800 focus:ring-slate-800/10 w-full"
|
||||
@click="toggleClockDivDropdown"
|
||||
:aria-expanded="showClockDivDropdown"
|
||||
aria-haspopup="listbox"
|
||||
role="combobox"
|
||||
>
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
<span>{{ currentClockDivLabel }}</span>
|
||||
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="currentColor" class="h-[1em] w-[1em] translate-x-0.5 stroke-[1.5]">
|
||||
<path d="M17 8L12 3L7 8" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path>
|
||||
<path d="M17 16L12 21L7 16" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path>
|
||||
</svg>
|
||||
</button>
|
||||
<input readonly style="display:none" :value="currentclockDiv" />
|
||||
<!-- 下拉菜单 -->
|
||||
<div v-if="showClockDivDropdown" class="absolute top-full left-0 right-0 mt-1 bg-white border border-slate-200 rounded-md shadow-lg z-50">
|
||||
<div
|
||||
v-for="option in ClockDivOptions"
|
||||
:key="option.value"
|
||||
@click="selectClockDiv(option.value)"
|
||||
class="px-3 py-2 text-sm text-slate-700 hover:bg-slate-100 cursor-pointer"
|
||||
:class="{ 'bg-slate-100': option.value === currentclockDiv }"
|
||||
>
|
||||
{{ option.label }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="flex items-center text-xs text-slate-400">
|
||||
{{ currentClockDivDescription }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
<label class="label">
|
||||
<span class="label-text text-sm">预捕获深度</span>
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="block text-sm font-semibold antialiased">
|
||||
捕获深度
|
||||
</label>
|
||||
<select
|
||||
v-model="preCaptureLength"
|
||||
class="select select-sm select-bordered"
|
||||
>
|
||||
<option
|
||||
v-for="option in preCaptureLengthOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
<div class="relative w-[200px]">
|
||||
<button
|
||||
@click="decreaseCaptureLength"
|
||||
class="absolute right-9 top-1 rounded-md border border-transparent p-1.5 text-center text-sm transition-all hover:bg-slate-100 focus:bg-slate-100 active:bg-slate-100 disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none"
|
||||
type="button"
|
||||
:disabled="captureLength <= CAPTURE_LENGTH_MIN"
|
||||
>
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="w-4 h-4">
|
||||
<path d="M3.75 7.25a.75.75 0 0 0 0 1.5h8.5a.75.75 0 0 0 0-1.5h-8.5Z" />
|
||||
</svg>
|
||||
</button>
|
||||
<input
|
||||
v-model.number="captureLength"
|
||||
@change="handleCaptureLengthChange"
|
||||
type="number"
|
||||
:min="CAPTURE_LENGTH_MIN"
|
||||
:max="CAPTURE_LENGTH_MAX"
|
||||
class="w-full bg-transparent placeholder:text-sm border border-slate-200 rounded-md pl-3 pr-20 py-2 transition duration-300 ease focus:outline-none focus:border-slate-400 ring ring-transparent hover:ring-slate-800/10 focus:ring-slate-800/10 hover:border-slate-800 shadow-sm focus:shadow appearance-none [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
|
||||
:placeholder="CAPTURE_LENGTH_MIN.toString()"
|
||||
/>
|
||||
<button
|
||||
@click="increaseCaptureLength"
|
||||
class="absolute right-1 top-1 rounded-md border border-transparent p-1.5 text-center text-sm transition-all hover:bg-slate-100 focus:bg-slate-100 active:bg-slate-100 disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none"
|
||||
type="button"
|
||||
:disabled="captureLength >= CAPTURE_LENGTH_MAX"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="w-4 h-4">
|
||||
<path d="M8.75 3.75a.75.75 0 0 0-1.5 0v3.5h-3.5a.75.75 0 0 0 0 1.5h3.5v3.5a.75.75 0 0 0 1.5 0v-3.5h3.5a.75.75 0 0 0 0-1.5h-3.5v-3.5Z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<p class="flex items-center text-xs text-slate-400">
|
||||
范围: {{ CAPTURE_LENGTH_MIN.toLocaleString() }} - {{ CAPTURE_LENGTH_MAX.toLocaleString() }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="block text-sm font-semibold antialiased">
|
||||
预捕获深度
|
||||
</label>
|
||||
<div class="relative w-[200px]">
|
||||
<button
|
||||
@click="decreasePreCaptureLength"
|
||||
class="absolute right-9 top-1 rounded-md border border-transparent p-1.5 text-center text-sm transition-all hover:bg-slate-100 focus:bg-slate-100 active:bg-slate-100 disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none"
|
||||
type="button"
|
||||
:disabled="preCaptureLength <= PRE_CAPTURE_LENGTH_MIN"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="w-4 h-4">
|
||||
<path d="M3.75 7.25a.75.75 0 0 0 0 1.5h8.5a.75.75 0 0 0 0-1.5h-8.5Z" />
|
||||
</svg>
|
||||
</button>
|
||||
<input
|
||||
v-model.number="preCaptureLength"
|
||||
@change="handlePreCaptureLengthChange"
|
||||
type="number"
|
||||
:min="PRE_CAPTURE_LENGTH_MIN"
|
||||
:max="Math.max(0, captureLength - 1)"
|
||||
class="w-full bg-transparent placeholder:text-sm border border-slate-200 rounded-md pl-3 pr-20 py-2 transition duration-300 ease focus:outline-none focus:border-slate-400 ring ring-transparent hover:ring-slate-800/10 focus:ring-slate-800/10 hover:border-slate-800 shadow-sm focus:shadow appearance-none [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
|
||||
:placeholder="PRE_CAPTURE_LENGTH_MIN.toString()"
|
||||
/>
|
||||
<button
|
||||
@click="increasePreCaptureLength"
|
||||
class="absolute right-1 top-1 rounded-md border border-transparent p-1.5 text-center text-sm transition-all hover:bg-slate-100 focus:bg-slate-100 active:bg-slate-100 disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none"
|
||||
type="button"
|
||||
:disabled="preCaptureLength >= Math.max(0, captureLength - 1)"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="w-4 h-4">
|
||||
<path d="M8.75 3.75a.75.75 0 0 0-1.5 0v3.5h-3.5a.75.75 0 0 0 0 1.5h3.5v3.5a.75.75 0 0 0 1.5 0v-3.5h3.5a.75.75 0 0 0 0-1.5h-3.5v-3.5Z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<p class="flex items-center text-xs text-slate-400">
|
||||
范围: {{ PRE_CAPTURE_LENGTH_MIN }} - {{ Math.max(0, captureLength - 1) }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="block text-sm font-semibold antialiased">
|
||||
重置配置
|
||||
</label>
|
||||
<div class="relative w-[200px]">
|
||||
<button
|
||||
@click="resetConfiguration"
|
||||
class="w-10 h-10 bg-transparent text-red-600 text-sm border border-red-200 rounded-md py-2 px-2.5 transition duration-300 ease ring ring-transparent hover:ring-red-600/10 focus:ring-red-600/10 hover:border-red-600 shadow-sm focus:shadow flex items-center justify-center"
|
||||
type="button"
|
||||
title="重置配置"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" class="w-4 h-4">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<p class="flex items-center text-xs text-slate-400">
|
||||
恢复所有设置到默认值
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧:操作按钮 -->
|
||||
<div class="flex flex-row gap-2">
|
||||
<button @click="resetConfiguration" class="btn btn-outline btn-sm">
|
||||
重置配置
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 通道列表 -->
|
||||
@@ -177,12 +308,14 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, onMounted, onUnmounted } from "vue";
|
||||
import { useRequiredInjection } from "@/utils/Common";
|
||||
import { useLogicAnalyzerState } from "./LogicAnalyzerManager";
|
||||
|
||||
const {
|
||||
currentGlobalMode,
|
||||
currentChannelDiv,
|
||||
currentclockDiv,
|
||||
captureLength,
|
||||
preCaptureLength,
|
||||
isApplying,
|
||||
@@ -193,10 +326,153 @@ const {
|
||||
operators,
|
||||
signalValues,
|
||||
channelDivOptions,
|
||||
captureLengthOptions,
|
||||
preCaptureLengthOptions,
|
||||
ClockDivOptions,
|
||||
CAPTURE_LENGTH_MIN,
|
||||
CAPTURE_LENGTH_MAX,
|
||||
PRE_CAPTURE_LENGTH_MIN,
|
||||
validateCaptureLength,
|
||||
validatePreCaptureLength,
|
||||
setCaptureLength,
|
||||
setPreCaptureLength,
|
||||
setChannelDiv,
|
||||
setGlobalMode,
|
||||
setClockDiv,
|
||||
resetConfiguration,
|
||||
} = useRequiredInjection(useLogicAnalyzerState);
|
||||
|
||||
// 下拉菜单状态
|
||||
const showGlobalModeDropdown = ref(false);
|
||||
const showChannelDivDropdown = ref(false);
|
||||
const showClockDivDropdown = ref(false);
|
||||
|
||||
// 处理捕获深度变化
|
||||
const handleCaptureLengthChange = () => {
|
||||
setCaptureLength(captureLength.value);
|
||||
};
|
||||
|
||||
// 处理预捕获深度变化
|
||||
const handlePreCaptureLengthChange = () => {
|
||||
setPreCaptureLength(preCaptureLength.value);
|
||||
};
|
||||
|
||||
// 增加捕获深度
|
||||
const increaseCaptureLength = () => {
|
||||
const newValue = Math.min(captureLength.value + 1024, CAPTURE_LENGTH_MAX);
|
||||
setCaptureLength(newValue);
|
||||
};
|
||||
|
||||
// 减少捕获深度
|
||||
const decreaseCaptureLength = () => {
|
||||
const newValue = Math.max(captureLength.value - 1024, CAPTURE_LENGTH_MIN);
|
||||
setCaptureLength(newValue);
|
||||
};
|
||||
|
||||
// 增加预捕获深度
|
||||
const increasePreCaptureLength = () => {
|
||||
const maxValue = Math.max(0, captureLength.value - 1);
|
||||
const newValue = Math.min(preCaptureLength.value + 64, maxValue);
|
||||
setPreCaptureLength(newValue);
|
||||
};
|
||||
|
||||
// 减少预捕获深度
|
||||
const decreasePreCaptureLength = () => {
|
||||
const newValue = Math.max(preCaptureLength.value - 64, PRE_CAPTURE_LENGTH_MIN);
|
||||
setPreCaptureLength(newValue);
|
||||
};
|
||||
|
||||
// 计算属性:获取当前全局模式的标签
|
||||
const currentGlobalModeLabel = computed(() => {
|
||||
const mode = globalModes.find(m => m.value === currentGlobalMode.value);
|
||||
return mode ? mode.label : '';
|
||||
});
|
||||
|
||||
// 计算属性:获取当前全局模式的描述
|
||||
const currentGlobalModeDescription = computed(() => {
|
||||
const mode = globalModes.find(m => m.value === currentGlobalMode.value);
|
||||
return mode ? mode.description : '';
|
||||
});
|
||||
|
||||
// 计算属性:获取当前通道组的标签
|
||||
const currentChannelDivLabel = computed(() => {
|
||||
const option = channelDivOptions.find(opt => opt.value === currentChannelDiv.value);
|
||||
return option ? option.label : '';
|
||||
});
|
||||
|
||||
// 计算属性:获取当前通道组的描述
|
||||
const currentChannelDivDescription = computed(() => {
|
||||
const option = channelDivOptions.find(opt => opt.value === currentChannelDiv.value);
|
||||
return option ? option.description : '';
|
||||
});
|
||||
|
||||
// 计算属性:获取当前采样频率的标签
|
||||
const currentClockDivLabel = computed(() => {
|
||||
const option = ClockDivOptions.find(opt => opt.value === currentclockDiv.value);
|
||||
return option ? option.label : '';
|
||||
});
|
||||
|
||||
// 计算属性:获取当前采样频率的描述
|
||||
const currentClockDivDescription = computed(() => {
|
||||
const option = ClockDivOptions.find(opt => opt.value === currentclockDiv.value);
|
||||
return option ? option.description : '';
|
||||
});
|
||||
|
||||
// 全局模式下拉菜单相关函数
|
||||
const toggleGlobalModeDropdown = () => {
|
||||
showGlobalModeDropdown.value = !showGlobalModeDropdown.value;
|
||||
if (showGlobalModeDropdown.value) {
|
||||
showChannelDivDropdown.value = false;
|
||||
showClockDivDropdown.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const selectGlobalMode = (mode: any) => {
|
||||
setGlobalMode(mode);
|
||||
showGlobalModeDropdown.value = false;
|
||||
};
|
||||
|
||||
// 通道组下拉菜单相关函数
|
||||
const toggleChannelDivDropdown = () => {
|
||||
showChannelDivDropdown.value = !showChannelDivDropdown.value;
|
||||
if (showChannelDivDropdown.value) {
|
||||
showGlobalModeDropdown.value = false;
|
||||
showClockDivDropdown.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const selectChannelDiv = (value: number) => {
|
||||
setChannelDiv(value);
|
||||
showChannelDivDropdown.value = false;
|
||||
};
|
||||
|
||||
// 采样频率下拉菜单相关函数
|
||||
const toggleClockDivDropdown = () => {
|
||||
showClockDivDropdown.value = !showClockDivDropdown.value;
|
||||
if (showClockDivDropdown.value) {
|
||||
showGlobalModeDropdown.value = false;
|
||||
showChannelDivDropdown.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const selectClockDiv = (value: any) => {
|
||||
setClockDiv(value);
|
||||
showClockDivDropdown.value = false;
|
||||
};
|
||||
|
||||
// 点击其他地方关闭下拉菜单
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
const target = event.target as HTMLElement;
|
||||
if (!target.closest('.relative')) {
|
||||
showGlobalModeDropdown.value = false;
|
||||
showChannelDivDropdown.value = false;
|
||||
showClockDivDropdown.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('click', handleClickOutside);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('click', handleClickOutside);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,276 +1,314 @@
|
||||
<template>
|
||||
<div class="flex flex-col bg-base-100 justify-center items-center gap-4">
|
||||
<!-- Title -->
|
||||
<h1 class="font-bold text-2xl">比特流文件</h1>
|
||||
|
||||
<!-- 示例比特流下载区域 (仅在有examId时显示) -->
|
||||
<div v-if="examId && availableBitstreams.length > 0" class="w-full">
|
||||
<fieldset class="fieldset w-full">
|
||||
<legend class="fieldset-legend text-sm">示例比特流文件</legend>
|
||||
<div class="space-y-2">
|
||||
<div v-for="bitstream in availableBitstreams" :key="bitstream.id" class="flex items-center justify-between p-2 border-2 border-base-300 rounded-lg">
|
||||
<span class="text-sm">{{ bitstream.name }}</span>
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
@click="downloadExampleBitstream(bitstream)"
|
||||
class="btn btn-sm btn-secondary"
|
||||
:disabled="isDownloading || isProgramming"
|
||||
>
|
||||
<div v-if="isDownloading">
|
||||
<span class="loading loading-spinner loading-xs"></span>
|
||||
下载中...
|
||||
</div>
|
||||
<div v-else>
|
||||
下载示例
|
||||
</div>
|
||||
</button>
|
||||
<button
|
||||
@click="programExampleBitstream(bitstream)"
|
||||
class="btn btn-sm btn-primary"
|
||||
:disabled="isDownloading || isProgramming || !uploadEvent"
|
||||
>
|
||||
<div v-if="isProgramming">
|
||||
<span class="loading loading-spinner loading-xs"></span>
|
||||
烧录中...
|
||||
</div>
|
||||
<div v-else>
|
||||
直接烧录
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<!-- 分割线 -->
|
||||
<div v-if="examId && availableBitstreams.length > 0" class="divider">或</div>
|
||||
|
||||
<!-- Input File -->
|
||||
<fieldset class="fieldset w-full">
|
||||
<legend class="fieldset-legend text-sm">上传自定义比特流文件</legend>
|
||||
<input type="file" ref="fileInput" class="file-input w-full" @change="handleFileChange" />
|
||||
<label class="fieldset-label">文件最大容量: {{ maxMemory }}MB</label>
|
||||
</fieldset>
|
||||
|
||||
<!-- Upload Button -->
|
||||
<div class="card-actions w-full">
|
||||
<button @click="handleClick" class="btn btn-primary grow" :disabled="isUploading || isProgramming">
|
||||
<div v-if="isUploading">
|
||||
<span class="loading loading-spinner"></span>
|
||||
上传中...
|
||||
</div>
|
||||
<div v-else>
|
||||
{{ buttonText }}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, useTemplateRef, onMounted } from "vue";
|
||||
import { AuthManager } from "@/utils/AuthManager"; // Adjust the path based on your project structure
|
||||
import { useDialogStore } from "@/stores/dialog";
|
||||
import { isNull, isUndefined } from "lodash";
|
||||
|
||||
interface Props {
|
||||
uploadEvent?: (file: File, examId: string) => Promise<number | null>;
|
||||
downloadEvent?: (bitstreamId: number) => Promise<boolean>;
|
||||
maxMemory?: number;
|
||||
examId?: string; // 新增examId属性
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
maxMemory: 4,
|
||||
examId: '',
|
||||
});
|
||||
|
||||
const emits = defineEmits<{
|
||||
finishedUpload: [file: File];
|
||||
}>();
|
||||
|
||||
const dialog = useDialogStore();
|
||||
|
||||
const isUploading = ref(false);
|
||||
const isDownloading = ref(false);
|
||||
const isProgramming = ref(false);
|
||||
const availableBitstreams = ref<{id: number, name: string}[]>([]);
|
||||
|
||||
const buttonText = computed(() => {
|
||||
return isUndefined(props.downloadEvent) ? "上传" : "上传并下载";
|
||||
});
|
||||
|
||||
const fileInput = useTemplateRef("fileInput");
|
||||
const bitstream = defineModel("bitstreamFile", {
|
||||
type: File,
|
||||
default: undefined,
|
||||
});
|
||||
|
||||
// 初始化时加载示例比特流
|
||||
onMounted(async () => {
|
||||
if (!isUndefined(bitstream.value) && !isNull(fileInput.value)) {
|
||||
let fileList = new DataTransfer();
|
||||
fileList.items.add(bitstream.value);
|
||||
fileInput.value.files = fileList.files;
|
||||
}
|
||||
|
||||
await loadAvailableBitstreams();
|
||||
});
|
||||
|
||||
// 加载可用的比特流文件列表
|
||||
async function loadAvailableBitstreams() {
|
||||
console.log('加载可用比特流文件,examId:', props.examId);
|
||||
if (!props.examId) {
|
||||
availableBitstreams.value = [];
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const resourceClient = AuthManager.createAuthenticatedResourceClient();
|
||||
// 使用新的ResourceClient API获取比特流模板资源列表
|
||||
const resources = await resourceClient.getResourceList(props.examId, 'bitstream', 'template');
|
||||
availableBitstreams.value = resources.map(r => ({ id: r.id, name: r.name })) || [];
|
||||
} catch (error) {
|
||||
console.error('加载比特流列表失败:', error);
|
||||
availableBitstreams.value = [];
|
||||
}
|
||||
}
|
||||
|
||||
// 下载示例比特流
|
||||
async function downloadExampleBitstream(bitstream: {id: number, name: string}) {
|
||||
if (isDownloading.value) return;
|
||||
|
||||
isDownloading.value = true;
|
||||
try {
|
||||
const resourceClient = AuthManager.createAuthenticatedResourceClient();
|
||||
|
||||
// 使用新的ResourceClient API获取资源文件
|
||||
const response = await resourceClient.getResourceById(bitstream.id);
|
||||
|
||||
if (response && response.data) {
|
||||
// 创建下载链接
|
||||
const url = URL.createObjectURL(response.data);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = response.fileName || bitstream.name;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
|
||||
dialog.info("示例比特流下载成功");
|
||||
} else {
|
||||
dialog.error("下载失败:响应数据为空");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('下载示例比特流失败:', error);
|
||||
dialog.error("下载示例比特流失败");
|
||||
} finally {
|
||||
isDownloading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 直接烧录示例比特流
|
||||
async function programExampleBitstream(bitstream: {id: number, name: string}) {
|
||||
if (isProgramming.value) return;
|
||||
|
||||
isProgramming.value = true;
|
||||
try {
|
||||
const resourceClient = AuthManager.createAuthenticatedResourceClient();
|
||||
|
||||
if (props.downloadEvent) {
|
||||
const downloadSuccess = await props.downloadEvent(bitstream.id);
|
||||
if (downloadSuccess) {
|
||||
dialog.info("示例比特流烧录成功");
|
||||
} else {
|
||||
dialog.error("烧录失败");
|
||||
}
|
||||
} else {
|
||||
dialog.info("示例比特流props.downloadEvent未定义 无法烧录");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('烧录示例比特流失败:', error);
|
||||
dialog.error("烧录示例比特流失败");
|
||||
} finally {
|
||||
isProgramming.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleFileChange(event: Event): void {
|
||||
const target = event.target as HTMLInputElement;
|
||||
const file = target.files?.[0]; // 获取选中的第一个文件
|
||||
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
bitstream.value = file;
|
||||
}
|
||||
|
||||
function checkFile(file: File): boolean {
|
||||
const maxBytes = props.maxMemory! * 1024 * 1024; // 将最大容量从 MB 转换为字节
|
||||
if (file.size > maxBytes) {
|
||||
dialog.error(`文件大小超过最大限制: ${props.maxMemory}MB`);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function handleClick(event: Event): Promise<void> {
|
||||
console.log("上传按钮被点击");
|
||||
if (isNull(bitstream.value) || isUndefined(bitstream.value)) {
|
||||
dialog.error(`未选择文件`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!checkFile(bitstream.value)) return;
|
||||
if (isUndefined(props.uploadEvent)) {
|
||||
dialog.error("无法上传");
|
||||
return;
|
||||
}
|
||||
|
||||
isUploading.value = true;
|
||||
let uploadedBitstreamId: number | null = null;
|
||||
try {
|
||||
console.log("开始上传比特流文件:", bitstream.value.name);
|
||||
const bitstreamId = await props.uploadEvent(bitstream.value, props.examId || '');
|
||||
console.log("上传结果,ID:", bitstreamId);
|
||||
if (isUndefined(props.downloadEvent)) {
|
||||
console.log("上传成功,下载未定义");
|
||||
isUploading.value = false;
|
||||
return;
|
||||
}
|
||||
if (bitstreamId === null || bitstreamId === undefined) {
|
||||
isUploading.value = false;
|
||||
return;
|
||||
}
|
||||
uploadedBitstreamId = bitstreamId;
|
||||
} catch (e) {
|
||||
dialog.error("上传失败");
|
||||
console.error(e);
|
||||
return;
|
||||
}
|
||||
|
||||
// Download
|
||||
try {
|
||||
console.log("开始下载比特流,ID:", uploadedBitstreamId);
|
||||
if (uploadedBitstreamId === null || uploadedBitstreamId === undefined) {
|
||||
dialog.error("uploadedBitstreamId is null or undefined");
|
||||
} else {
|
||||
const ret = await props.downloadEvent(uploadedBitstreamId);
|
||||
if (ret) dialog.info("下载成功");
|
||||
else dialog.error("下载失败");
|
||||
}
|
||||
} catch (e) {
|
||||
dialog.error("下载失败");
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
isUploading.value = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="postcss">
|
||||
@import "../assets/main.css";
|
||||
</style>
|
||||
<template>
|
||||
<div class="flex flex-col bg-base-100 justify-center items-center gap-4">
|
||||
<!-- Title -->
|
||||
<h1 class="font-bold text-2xl">比特流文件</h1>
|
||||
|
||||
<!-- 示例比特流下载区域 (仅在有examId时显示) -->
|
||||
<div v-if="examId && availableBitstreams.length > 0" class="w-full">
|
||||
<fieldset class="fieldset w-full">
|
||||
<legend class="fieldset-legend text-sm">示例比特流文件</legend>
|
||||
<div class="space-y-2">
|
||||
<div
|
||||
v-for="bitstream in availableBitstreams"
|
||||
:key="bitstream.id"
|
||||
class="flex items-center justify-between p-2 border-2 border-base-300 rounded-lg"
|
||||
>
|
||||
<span class="text-sm">{{ bitstream.name }}</span>
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
@click="downloadExampleBitstream(bitstream)"
|
||||
class="btn btn-sm btn-secondary"
|
||||
:disabled="isDownloading || isProgramming"
|
||||
>
|
||||
<div v-if="isDownloading">
|
||||
<span class="loading loading-spinner loading-xs"></span>
|
||||
{{ downloadProgress }}%
|
||||
</div>
|
||||
<div v-else>下载示例</div>
|
||||
</button>
|
||||
<button
|
||||
@click="programExampleBitstream(bitstream)"
|
||||
class="btn btn-sm btn-primary"
|
||||
:disabled="isDownloading || isProgramming"
|
||||
>
|
||||
<div v-if="isProgramming">
|
||||
<span class="loading loading-spinner loading-xs"></span>
|
||||
烧录中...
|
||||
</div>
|
||||
<div v-else>直接烧录</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<!-- 分割线 -->
|
||||
<div v-if="examId && availableBitstreams.length > 0" class="divider">
|
||||
或
|
||||
</div>
|
||||
|
||||
<!-- Input File -->
|
||||
<fieldset class="fieldset w-full">
|
||||
<legend class="fieldset-legend text-sm">上传自定义比特流文件</legend>
|
||||
<input
|
||||
type="file"
|
||||
ref="fileInput"
|
||||
class="file-input w-full"
|
||||
@change="handleFileChange"
|
||||
/>
|
||||
<label class="fieldset-label">文件最大容量: {{ maxMemory }}MB</label>
|
||||
</fieldset>
|
||||
|
||||
<!-- Upload Button -->
|
||||
<div class="card-actions w-full">
|
||||
<button
|
||||
@click="handleClick"
|
||||
class="btn btn-primary grow"
|
||||
:disabled="isUploading || isProgramming"
|
||||
>
|
||||
<div v-if="isUploading">
|
||||
<span class="loading loading-spinner"></span>
|
||||
上传中...
|
||||
</div>
|
||||
<div v-else>上传并下载</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, useTemplateRef, onMounted } from "vue";
|
||||
import { AuthManager } from "@/utils/AuthManager"; // Adjust the path based on your project structure
|
||||
import { useDialogStore } from "@/stores/dialog";
|
||||
import { isNull, isUndefined } from "lodash";
|
||||
import { useEquipments } from "@/stores/equipments";
|
||||
import type { HubConnection } from "@microsoft/signalr";
|
||||
import type {
|
||||
IProgressHub,
|
||||
IProgressReceiver,
|
||||
} from "@/TypedSignalR.Client/server.Hubs";
|
||||
import { getHubProxyFactory, getReceiverRegister } from "@/TypedSignalR.Client";
|
||||
import { ProgressStatus } from "@/server.Hubs";
|
||||
import { useRequiredInjection } from "@/utils/Common";
|
||||
import { useAlertStore } from "./Alert";
|
||||
|
||||
interface Props {
|
||||
maxMemory?: number;
|
||||
examId?: string; // 新增examId属性
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
maxMemory: 4,
|
||||
examId: "",
|
||||
});
|
||||
|
||||
const emits = defineEmits<{
|
||||
finishedUpload: [file: File];
|
||||
}>();
|
||||
|
||||
const alert = useRequiredInjection(useAlertStore);
|
||||
const dialog = useDialogStore();
|
||||
const eqps = useEquipments();
|
||||
|
||||
const isUploading = ref(false);
|
||||
const isDownloading = ref(false);
|
||||
const isProgramming = ref(false);
|
||||
const availableBitstreams = ref<{ id: number; name: string }[]>([]);
|
||||
|
||||
// Progress
|
||||
const downloadTaskId = ref("");
|
||||
const downloadProgress = ref(0);
|
||||
const progressHubConnection = ref<HubConnection>();
|
||||
const progressHubProxy = ref<IProgressHub>();
|
||||
const progressHubReceiver: IProgressReceiver = {
|
||||
onReceiveProgress: async (msg) => {
|
||||
if (msg.taskId == downloadTaskId.value) {
|
||||
if (msg.status == ProgressStatus.InProgress) {
|
||||
downloadProgress.value = msg.progressPercent;
|
||||
} else if (msg.status == ProgressStatus.Failed) {
|
||||
dialog.error(msg.errorMessage);
|
||||
} else if (msg.status == ProgressStatus.Completed) {
|
||||
alert.info("比特流下载成功");
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
onMounted(async () => {
|
||||
progressHubConnection.value =
|
||||
AuthManager.createAuthenticatedProgressHubConnection();
|
||||
progressHubProxy.value = getHubProxyFactory("IProgressHub").createHubProxy(
|
||||
progressHubConnection.value,
|
||||
);
|
||||
getReceiverRegister("IProgressReceiver").register(
|
||||
progressHubConnection.value,
|
||||
progressHubReceiver,
|
||||
);
|
||||
});
|
||||
|
||||
const fileInput = useTemplateRef("fileInput");
|
||||
const bitstream = defineModel("bitstreamFile", {
|
||||
type: File,
|
||||
default: undefined,
|
||||
});
|
||||
|
||||
// 初始化时加载示例比特流
|
||||
onMounted(async () => {
|
||||
if (!isUndefined(bitstream.value) && !isNull(fileInput.value)) {
|
||||
let fileList = new DataTransfer();
|
||||
fileList.items.add(bitstream.value);
|
||||
fileInput.value.files = fileList.files;
|
||||
}
|
||||
|
||||
await loadAvailableBitstreams();
|
||||
});
|
||||
|
||||
// 加载可用的比特流文件列表
|
||||
async function loadAvailableBitstreams() {
|
||||
console.log("加载可用比特流文件,examId:", props.examId);
|
||||
if (!props.examId) {
|
||||
availableBitstreams.value = [];
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const resourceClient = AuthManager.createAuthenticatedResourceClient();
|
||||
// 使用新的ResourceClient API获取比特流模板资源列表
|
||||
const resources = await resourceClient.getResourceList(
|
||||
props.examId,
|
||||
"bitstream",
|
||||
"template",
|
||||
);
|
||||
availableBitstreams.value =
|
||||
resources.map((r) => ({ id: r.id, name: r.name })) || [];
|
||||
} catch (error) {
|
||||
console.error("加载比特流列表失败:", error);
|
||||
availableBitstreams.value = [];
|
||||
}
|
||||
}
|
||||
|
||||
// 下载示例比特流
|
||||
async function downloadExampleBitstream(bitstream: {
|
||||
id: number;
|
||||
name: string;
|
||||
}) {
|
||||
if (isDownloading.value) return;
|
||||
|
||||
isDownloading.value = true;
|
||||
try {
|
||||
const resourceClient = AuthManager.createAuthenticatedResourceClient();
|
||||
|
||||
// 使用新的ResourceClient API获取资源文件
|
||||
const response = await resourceClient.getResourceById(bitstream.id);
|
||||
|
||||
if (response && response.data) {
|
||||
// 创建下载链接
|
||||
const url = URL.createObjectURL(response.data);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = response.fileName || bitstream.name;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
|
||||
dialog.info("示例比特流下载成功");
|
||||
} else {
|
||||
dialog.error("下载失败:响应数据为空");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("下载示例比特流失败:", error);
|
||||
dialog.error("下载示例比特流失败");
|
||||
} finally {
|
||||
isDownloading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 直接烧录示例比特流
|
||||
async function programExampleBitstream(bitstream: {
|
||||
id: number;
|
||||
name: string;
|
||||
}) {
|
||||
if (isProgramming.value) return;
|
||||
|
||||
isProgramming.value = true;
|
||||
try {
|
||||
const downloadTaskId = await eqps.jtagDownloadBitstream(bitstream.id);
|
||||
} catch (error) {
|
||||
console.error("烧录示例比特流失败:", error);
|
||||
dialog.error("烧录示例比特流失败");
|
||||
} finally {
|
||||
isProgramming.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleFileChange(event: Event): void {
|
||||
const target = event.target as HTMLInputElement;
|
||||
const file = target.files?.[0]; // 获取选中的第一个文件
|
||||
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
bitstream.value = file;
|
||||
}
|
||||
|
||||
function checkFile(file: File): boolean {
|
||||
const maxBytes = props.maxMemory! * 1024 * 1024; // 将最大容量从 MB 转换为字节
|
||||
if (file.size > maxBytes) {
|
||||
dialog.error(`文件大小超过最大限制: ${props.maxMemory}MB`);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function handleClick(event: Event): Promise<void> {
|
||||
console.log("上传按钮被点击");
|
||||
if (isNull(bitstream.value) || isUndefined(bitstream.value)) {
|
||||
dialog.error(`未选择文件`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!checkFile(bitstream.value)) return;
|
||||
|
||||
isUploading.value = true;
|
||||
let uploadedBitstreamId: number | null = null;
|
||||
try {
|
||||
console.log("开始上传比特流文件:", bitstream.value.name);
|
||||
const bitstreamId = await eqps.jtagUploadBitstream(
|
||||
bitstream.value,
|
||||
props.examId || "",
|
||||
);
|
||||
console.log("上传结果,ID:", bitstreamId);
|
||||
if (bitstreamId === null || bitstreamId === undefined) {
|
||||
isUploading.value = false;
|
||||
return;
|
||||
}
|
||||
uploadedBitstreamId = bitstreamId;
|
||||
} catch (e) {
|
||||
dialog.error("上传失败");
|
||||
console.error(e);
|
||||
return;
|
||||
}
|
||||
isUploading.value = false;
|
||||
|
||||
// Download
|
||||
try {
|
||||
console.log("开始下载比特流,ID:", uploadedBitstreamId);
|
||||
if (uploadedBitstreamId === null || uploadedBitstreamId === undefined) {
|
||||
dialog.error("uploadedBitstreamId is null or undefined");
|
||||
} else {
|
||||
isDownloading.value = true;
|
||||
downloadTaskId.value =
|
||||
await eqps.jtagDownloadBitstream(uploadedBitstreamId);
|
||||
}
|
||||
} catch (e) {
|
||||
dialog.error("下载失败");
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="postcss">
|
||||
@import "../assets/main.css";
|
||||
</style>
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
<UploadCard
|
||||
:exam-id="props.examId"
|
||||
:upload-event="eqps.jtagUploadBitstream"
|
||||
:download-event="handleDownloadBitstream"
|
||||
:bitstream-file="eqps.jtagBitstream"
|
||||
@update:bitstream-file="handleBitstreamChange"
|
||||
>
|
||||
@@ -128,11 +127,6 @@ function handleBitstreamChange(file: File | undefined) {
|
||||
eqps.jtagBitstream = file;
|
||||
}
|
||||
|
||||
async function handleDownloadBitstream(bitstreamId: number): Promise<boolean> {
|
||||
console.log("开始下载比特流,ID:", bitstreamId);
|
||||
return await eqps.jtagDownloadBitstream(bitstreamId);
|
||||
}
|
||||
|
||||
function handleSelectJtagSpeed(event: Event) {
|
||||
const target = event.target as HTMLSelectElement;
|
||||
eqps.jtagSetSpeed(target.selectedIndex);
|
||||
|
||||
13
src/main.ts
13
src/main.ts
@@ -1,10 +1,9 @@
|
||||
import './assets/main.css'
|
||||
import "./assets/main.css";
|
||||
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import { createApp } from "vue";
|
||||
import { createPinia } from "pinia";
|
||||
|
||||
import App from '@/App.vue'
|
||||
import router from './router'
|
||||
|
||||
const app = createApp(App).use(router).use(createPinia()).mount('#app')
|
||||
import App from "@/App.vue";
|
||||
import router from "./router";
|
||||
|
||||
const app = createApp(App).use(router).use(createPinia()).mount("#app");
|
||||
|
||||
25
src/server.Hubs.ts
Normal file
25
src/server.Hubs.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/* THIS (.ts) FILE IS GENERATED BY Tapper */
|
||||
/* eslint-disable */
|
||||
/* tslint:disable */
|
||||
|
||||
/** Transpiled from server.Hubs.ProgressStatus */
|
||||
export enum ProgressStatus {
|
||||
Pending = 0,
|
||||
InProgress = 1,
|
||||
Completed = 2,
|
||||
Canceled = 3,
|
||||
Failed = 4,
|
||||
}
|
||||
|
||||
/** Transpiled from server.Hubs.ProgressInfo */
|
||||
export type ProgressInfo = {
|
||||
/** Transpiled from string */
|
||||
taskId: string;
|
||||
/** Transpiled from server.Hubs.ProgressStatus */
|
||||
status: ProgressStatus;
|
||||
/** Transpiled from int */
|
||||
progressPercent: number;
|
||||
/** Transpiled from string */
|
||||
errorMessage: string;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import { AuthManager } from "@/utils/AuthManager";
|
||||
import { HubConnection, HubConnectionBuilder } from "@microsoft/signalr";
|
||||
import { getHubProxyFactory, getReceiverRegister } from "@/TypedSignalR.Client";
|
||||
import type { ResourceInfo } from "@/APIClient";
|
||||
import type { IJtagHub } from "@/TypedSignalR.Client/server.Hubs.JtagHub";
|
||||
import type { IJtagHub } from "@/TypedSignalR.Client/server.Hubs";
|
||||
|
||||
export const useEquipments = defineStore("equipments", () => {
|
||||
// Global Stores
|
||||
@@ -123,24 +123,27 @@ export const useEquipments = defineStore("equipments", () => {
|
||||
enableJtagBoundaryScan.value = enable;
|
||||
}
|
||||
|
||||
async function jtagUploadBitstream(bitstream: File, examId?: string): Promise<number | null> {
|
||||
async function jtagUploadBitstream(
|
||||
bitstream: File,
|
||||
examId?: string,
|
||||
): Promise<number | null> {
|
||||
try {
|
||||
// 自动开启电源
|
||||
await powerSetOnOff(true);
|
||||
|
||||
const resourceClient = AuthManager.createAuthenticatedResourceClient();
|
||||
const resp = await resourceClient.addResource(
|
||||
'bitstream',
|
||||
'user',
|
||||
"bitstream",
|
||||
"user",
|
||||
examId || null,
|
||||
toFileParameterOrUndefined(bitstream),
|
||||
);
|
||||
|
||||
|
||||
// 如果上传成功,设置为当前选中的比特流
|
||||
if (resp && resp.id !== undefined && resp.id !== null) {
|
||||
return resp.id;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
} catch (e) {
|
||||
dialog.error("上传错误");
|
||||
@@ -149,10 +152,10 @@ export const useEquipments = defineStore("equipments", () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function jtagDownloadBitstream(bitstreamId?: number): Promise<boolean> {
|
||||
async function jtagDownloadBitstream(bitstreamId?: number): Promise<string> {
|
||||
if (bitstreamId === null || bitstreamId === undefined) {
|
||||
dialog.error("请先选择要下载的比特流");
|
||||
return false;
|
||||
return "";
|
||||
}
|
||||
|
||||
const release = await jtagClientMutex.acquire();
|
||||
@@ -170,7 +173,7 @@ export const useEquipments = defineStore("equipments", () => {
|
||||
} catch (e) {
|
||||
dialog.error("下载错误");
|
||||
console.error(e);
|
||||
return false;
|
||||
throw e;
|
||||
} finally {
|
||||
release();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
DebuggerClient,
|
||||
ExamClient,
|
||||
ResourceClient,
|
||||
HdmiVideoStreamClient,
|
||||
} from "@/APIClient";
|
||||
import router from "@/router";
|
||||
import { HubConnectionBuilder } from "@microsoft/signalr";
|
||||
@@ -38,7 +39,8 @@ type SupportedClient =
|
||||
| OscilloscopeApiClient
|
||||
| DebuggerClient
|
||||
| ExamClient
|
||||
| ResourceClient;
|
||||
| ResourceClient
|
||||
| HdmiVideoStreamClient;
|
||||
|
||||
export class AuthManager {
|
||||
// 存储token到localStorage
|
||||
@@ -204,7 +206,11 @@ export class AuthManager {
|
||||
public static createAuthenticatedResourceClient(): ResourceClient {
|
||||
return AuthManager.createAuthenticatedClient(ResourceClient);
|
||||
}
|
||||
|
||||
|
||||
public static createAuthenticatedHdmiVideoStreamClient(): HdmiVideoStreamClient {
|
||||
return AuthManager.createAuthenticatedClient(HdmiVideoStreamClient);
|
||||
}
|
||||
|
||||
public static createAuthenticatedJtagHubConnection() {
|
||||
const token = this.getToken();
|
||||
if (isNull(token)) {
|
||||
@@ -220,6 +226,21 @@ export class AuthManager {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static createAuthenticatedProgressHubConnection() {
|
||||
const token = this.getToken();
|
||||
if (isNull(token)) {
|
||||
router.push("/login");
|
||||
throw Error("Token Null!");
|
||||
}
|
||||
|
||||
return new HubConnectionBuilder()
|
||||
.withUrl("http://127.0.0.1:5000/hubs/ProgressHub", {
|
||||
accessTokenFactory: () => token,
|
||||
})
|
||||
.withAutomaticReconnect()
|
||||
.build();
|
||||
}
|
||||
|
||||
// 登录函数
|
||||
public static async login(
|
||||
username: string,
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
:checked="checkID === 3"
|
||||
@change="handleTabChange"
|
||||
/>
|
||||
<SquareActivityIcon class="icon" />
|
||||
示波器
|
||||
<Monitor class="icon" />
|
||||
HDMI视频流
|
||||
</label>
|
||||
<label class="tab">
|
||||
<input
|
||||
@@ -42,8 +42,8 @@
|
||||
:checked="checkID === 4"
|
||||
@change="handleTabChange"
|
||||
/>
|
||||
<Binary class="icon" />
|
||||
逻辑分析仪
|
||||
<SquareActivityIcon class="icon" />
|
||||
示波器
|
||||
</label>
|
||||
<label class="tab">
|
||||
<input
|
||||
@@ -53,6 +53,17 @@
|
||||
:checked="checkID === 5"
|
||||
@change="handleTabChange"
|
||||
/>
|
||||
<Binary class="icon" />
|
||||
逻辑分析仪
|
||||
</label>
|
||||
<label class="tab">
|
||||
<input
|
||||
type="radio"
|
||||
name="function-bar"
|
||||
id="6"
|
||||
:checked="checkID === 6"
|
||||
@change="handleTabChange"
|
||||
/>
|
||||
<Hand class="icon" />
|
||||
嵌入式逻辑分析仪
|
||||
</label>
|
||||
@@ -73,12 +84,15 @@
|
||||
<VideoStreamView />
|
||||
</div>
|
||||
<div v-else-if="checkID === 3" class="h-full overflow-y-auto">
|
||||
<OscilloscopeView />
|
||||
<HdmiVideoStreamView />
|
||||
</div>
|
||||
<div v-else-if="checkID === 4" class="h-full overflow-y-auto">
|
||||
<LogicAnalyzerView />
|
||||
<OscilloscopeView />
|
||||
</div>
|
||||
<div v-else-if="checkID === 5" class="h-full overflow-y-auto">
|
||||
<LogicAnalyzerView />
|
||||
</div>
|
||||
<div v-else-if="checkID === 6" class="h-full overflow-y-auto">
|
||||
<Debugger />
|
||||
</div>
|
||||
</div>
|
||||
@@ -94,9 +108,11 @@ import {
|
||||
MinimizeIcon,
|
||||
Binary,
|
||||
Hand,
|
||||
Monitor,
|
||||
} from "lucide-vue-next";
|
||||
import { useLocalStorage } from "@vueuse/core";
|
||||
import VideoStreamView from "@/views/Project/VideoStream.vue";
|
||||
import HdmiVideoStreamView from "@/views/Project/HdmiVideoStream.vue";
|
||||
import OscilloscopeView from "@/views/Project/Oscilloscope.vue";
|
||||
import LogicAnalyzerView from "@/views/Project/LogicAnalyzer.vue";
|
||||
import { isNull, toNumber } from "lodash";
|
||||
|
||||
490
src/views/Project/HdmiVideoStream.vue
Normal file
490
src/views/Project/HdmiVideoStream.vue
Normal file
@@ -0,0 +1,490 @@
|
||||
<template>
|
||||
<div class="bg-base-100 flex flex-col gap-7">
|
||||
<!-- 控制面板 -->
|
||||
<div class="card bg-base-200 shadow-xl mx-5">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-primary">
|
||||
<Settings class="w-6 h-6" />
|
||||
HDMI视频流控制面板
|
||||
</h2>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<!-- 板卡信息 -->
|
||||
<div class="stats shadow">
|
||||
<div class="stat bg-base-100">
|
||||
<div class="stat-figure text-primary">
|
||||
<div class="badge" :class="endpoint ? 'badge-success' : 'badge-warning'">
|
||||
{{ endpoint ? "已连接" : "未配置" }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-title">板卡状态</div>
|
||||
<div class="stat-value text-primary">HDMI</div>
|
||||
<div class="stat-desc">{{ endpoint ? `板卡: ${endpoint.boardId.substring(0, 8)}...` : "请先连接板卡" }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 连接状态 -->
|
||||
<div class="stats shadow">
|
||||
<div class="stat bg-base-100">
|
||||
<div class="stat-figure text-secondary">
|
||||
<Video class="w-8 h-8" />
|
||||
</div>
|
||||
<div class="stat-title">视频状态</div>
|
||||
<div class="stat-value text-secondary">
|
||||
{{ isPlaying ? "播放中" : "未播放" }}
|
||||
</div>
|
||||
<div class="stat-desc">{{ videoStatus }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<div class="card-actions justify-end mt-4">
|
||||
<button class="btn btn-outline btn-primary" @click="refreshEndpoint" :disabled="loading">
|
||||
<RefreshCw v-if="loading" class="animate-spin h-4 w-4 mr-2" />
|
||||
<RefreshCw v-else class="h-4 w-4 mr-2" />
|
||||
{{ loading ? "刷新中..." : "刷新连接" }}
|
||||
</button>
|
||||
<button class="btn btn-primary" @click="testConnection" :disabled="testing || !endpoint">
|
||||
<RefreshCw v-if="testing" class="animate-spin h-4 w-4 mr-2" />
|
||||
<TestTube v-else class="h-4 w-4 mr-2" />
|
||||
{{ testing ? "测试中..." : "测试连接" }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 视频预览区域 -->
|
||||
<div class="card bg-base-200 shadow-xl mx-5">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-primary">
|
||||
<Video class="w-6 h-6" />
|
||||
HDMI视频预览
|
||||
</h2>
|
||||
|
||||
<div class="relative bg-black rounded-lg overflow-hidden cursor-pointer" :class="[
|
||||
{ 'cursor-not-allowed': !isPlaying || hasVideoError || !endpoint }
|
||||
]" style="aspect-ratio: 16/9" @click="handleVideoClick">
|
||||
<!-- 视频播放器 - 使用img标签直接显示MJPEG流 -->
|
||||
<div v-show="isPlaying && endpoint" class="w-full h-full flex items-center justify-center">
|
||||
<img :src="currentVideoSource" alt="HDMI视频流" class="max-w-full max-h-full object-contain"
|
||||
@error="handleVideoError" @load="handleVideoLoad" />
|
||||
</div>
|
||||
|
||||
<!-- 错误信息显示 -->
|
||||
<div v-if="hasVideoError" class="absolute inset-0 flex items-center justify-center bg-black bg-opacity-70">
|
||||
<div class="card bg-error text-white shadow-lg w-full max-w-lg">
|
||||
<div class="card-body">
|
||||
<h3 class="card-title flex items-center gap-2">
|
||||
<AlertTriangle class="h-6 w-6" />
|
||||
HDMI视频流加载失败
|
||||
</h3>
|
||||
<p>无法连接到HDMI视频服务器,请检查以下内容:</p>
|
||||
<ul class="list-disc list-inside">
|
||||
<li>HDMI输入设备是否已连接</li>
|
||||
<li>板卡是否正常工作</li>
|
||||
<li>网络连接是否正常</li>
|
||||
<li>HDMI视频流服务是否已启动</li>
|
||||
</ul>
|
||||
<div class="card-actions justify-end mt-2">
|
||||
<button class="btn btn-sm btn-outline btn-primary" @click="tryReconnect">
|
||||
重试连接
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 占位符 -->
|
||||
<div v-show="(!isPlaying && !hasVideoError) || !endpoint"
|
||||
class="absolute inset-0 flex items-center justify-center text-white">
|
||||
<div class="text-center">
|
||||
<Video class="w-16 h-16 mx-auto mb-4 opacity-50" />
|
||||
<p class="text-lg opacity-75">{{ videoStatus }}</p>
|
||||
<p class="text-sm opacity-60 mt-2">
|
||||
{{ endpoint ? '点击"播放HDMI视频流"按钮开始查看实时视频' : '请先刷新连接以获取板卡信息' }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 视频控制 -->
|
||||
<div class="flex justify-between items-center mt-4" v-if="endpoint">
|
||||
<div class="text-sm text-base-content/70">
|
||||
MJPEG地址:
|
||||
<code class="bg-base-300 px-2 py-1 rounded text-xs">{{
|
||||
endpoint.mjpegUrl
|
||||
}}</code>
|
||||
</div>
|
||||
<div class="space-x-2">
|
||||
<div class="dropdown dropdown-hover dropdown-top dropdown-end">
|
||||
<div tabindex="0" role="button" class="btn btn-sm btn-outline btn-accent">
|
||||
<MoreHorizontal class="w-4 h-4 mr-1" />
|
||||
更多功能
|
||||
</div>
|
||||
<ul tabindex="0" class="dropdown-content z-[1] menu p-2 shadow bg-base-200 rounded-box w-52">
|
||||
<li>
|
||||
<a @click="openInNewTab(endpoint.videoUrl)">
|
||||
<ExternalLink class="w-4 h-4" />
|
||||
在新标签打开视频页面
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a @click="takeSnapshot">
|
||||
<Camera class="w-4 h-4" />
|
||||
获取并下载快照
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a @click="copyToClipboard(endpoint.mjpegUrl)">
|
||||
<Copy class="w-4 h-4" />
|
||||
复制MJPEG地址
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<button class="btn btn-success btn-sm" @click="startStream" :disabled="isPlaying || !endpoint">
|
||||
<Play class="w-4 h-4 mr-1" />
|
||||
播放HDMI视频流
|
||||
</button>
|
||||
<button class="btn btn-error btn-sm" @click="stopStream" :disabled="!isPlaying">
|
||||
<Square class="w-4 h-4 mr-1" />
|
||||
停止视频流
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 日志区域 -->
|
||||
<div class="card bg-base-200 shadow-xl mx-5">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-primary">
|
||||
<FileText class="w-6 h-6" />
|
||||
操作日志
|
||||
</h2>
|
||||
|
||||
<div class="bg-base-300 rounded-lg p-4 h-48 overflow-y-auto">
|
||||
<div v-for="(log, index) in logs" :key="index" class="text-sm font-mono mb-1">
|
||||
<span class="text-base-content/50">[{{ formatTime(log.time) }}]</span>
|
||||
<span :class="getLogClass(log.level)">{{ log.message }}</span>
|
||||
</div>
|
||||
<div v-if="logs.length === 0" class="text-base-content/50 text-center py-8">
|
||||
暂无日志记录
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-actions justify-end mt-2">
|
||||
<button class="btn btn-outline btn-sm" @click="clearLogs">
|
||||
清空日志
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onUnmounted } from "vue";
|
||||
import {
|
||||
Settings,
|
||||
Video,
|
||||
RefreshCw,
|
||||
TestTube,
|
||||
Play,
|
||||
Square,
|
||||
ExternalLink,
|
||||
Camera,
|
||||
Copy,
|
||||
FileText,
|
||||
AlertTriangle,
|
||||
MoreHorizontal,
|
||||
} from "lucide-vue-next";
|
||||
import { HdmiVideoStreamClient, type HdmiVideoStreamEndpoint } from "@/APIClient";
|
||||
import { AuthManager } from "@/utils/AuthManager";
|
||||
import { useAlertStore } from "@/components/Alert";
|
||||
|
||||
// Alert系统
|
||||
const alert = useAlertStore();
|
||||
|
||||
// 状态管理
|
||||
const loading = ref(false);
|
||||
const testing = ref(false);
|
||||
const isPlaying = ref(false);
|
||||
const hasVideoError = ref(false);
|
||||
const videoStatus = ref('未连接');
|
||||
|
||||
// HDMI视频流数据
|
||||
const endpoint = ref<HdmiVideoStreamEndpoint | null>(null);
|
||||
const currentVideoSource = ref('');
|
||||
|
||||
// 日志系统
|
||||
interface LogEntry {
|
||||
time: Date;
|
||||
level: 'info' | 'success' | 'warning' | 'error';
|
||||
message: string;
|
||||
}
|
||||
|
||||
const logs = ref<LogEntry[]>([]);
|
||||
|
||||
// 添加日志
|
||||
function addLog(level: LogEntry['level'], message: string) {
|
||||
logs.value.unshift({
|
||||
time: new Date(),
|
||||
level,
|
||||
message
|
||||
});
|
||||
|
||||
// 保持最近100条日志
|
||||
if (logs.value.length > 100) {
|
||||
logs.value = logs.value.slice(0, 100);
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化时间
|
||||
function formatTime(date: Date): string {
|
||||
return date.toLocaleTimeString();
|
||||
}
|
||||
|
||||
// 获取日志样式类
|
||||
function getLogClass(level: LogEntry['level']): string {
|
||||
switch (level) {
|
||||
case 'success':
|
||||
return 'text-success';
|
||||
case 'warning':
|
||||
return 'text-warning';
|
||||
case 'error':
|
||||
return 'text-error';
|
||||
default:
|
||||
return 'text-base-content';
|
||||
}
|
||||
}
|
||||
|
||||
// 清空日志
|
||||
function clearLogs() {
|
||||
logs.value = [];
|
||||
addLog('info', '日志已清空');
|
||||
}
|
||||
|
||||
// 刷新HDMI视频流端点
|
||||
async function refreshEndpoint() {
|
||||
loading.value = true;
|
||||
try {
|
||||
addLog('info', '正在获取HDMI视频流端点...');
|
||||
|
||||
const client = AuthManager.createAuthenticatedHdmiVideoStreamClient();
|
||||
const result = await client.getMyEndpoint();
|
||||
|
||||
if (result) {
|
||||
endpoint.value = result;
|
||||
videoStatus.value = '已连接板卡,可以播放视频流';
|
||||
addLog('success', `成功获取HDMI视频流端点,板卡ID: ${result.boardId.substring(0, 8)}...`);
|
||||
alert?.success('HDMI视频流连接成功');
|
||||
} else {
|
||||
endpoint.value = null;
|
||||
videoStatus.value = '无法获取板卡信息';
|
||||
addLog('error', '未找到绑定的板卡或板卡未配置HDMI输入');
|
||||
alert?.error('未找到绑定的板卡');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取HDMI视频流端点失败:', error);
|
||||
endpoint.value = null;
|
||||
videoStatus.value = '连接失败';
|
||||
addLog('error', `获取HDMI视频流端点失败: ${error}`);
|
||||
alert?.error('获取HDMI视频流信息失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 测试连接
|
||||
async function testConnection() {
|
||||
if (!endpoint.value) {
|
||||
alert?.warn('请先刷新连接获取板卡信息');
|
||||
return;
|
||||
}
|
||||
|
||||
testing.value = true;
|
||||
try {
|
||||
addLog('info', '正在测试HDMI视频流连接...');
|
||||
|
||||
// 尝试获取快照来测试连接
|
||||
const response = await fetch(endpoint.value.snapshotUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache'
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
addLog('success', 'HDMI视频流连接测试成功');
|
||||
alert?.success('HDMI连接测试成功');
|
||||
videoStatus.value = '连接正常,可以播放视频流';
|
||||
} else {
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('HDMI视频流连接测试失败:', error);
|
||||
addLog('error', `连接测试失败: ${error}`);
|
||||
alert?.error('HDMI连接测试失败');
|
||||
videoStatus.value = '连接测试失败';
|
||||
} finally {
|
||||
testing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 开始播放视频流
|
||||
function startStream() {
|
||||
if (!endpoint.value) {
|
||||
alert?.warn('请先刷新连接获取板卡信息');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 添加时间戳防止缓存
|
||||
const timestamp = new Date().getTime();
|
||||
currentVideoSource.value = `${endpoint.value.mjpegUrl}&t=${timestamp}`;
|
||||
isPlaying.value = true;
|
||||
hasVideoError.value = false;
|
||||
videoStatus.value = '正在加载视频流...';
|
||||
|
||||
addLog('info', '开始播放HDMI视频流');
|
||||
alert?.success('开始播放HDMI视频流');
|
||||
} catch (error) {
|
||||
console.error('启动HDMI视频流失败:', error);
|
||||
addLog('error', `启动视频流失败: ${error}`);
|
||||
alert?.error('启动HDMI视频流失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 停止播放视频流
|
||||
function stopStream() {
|
||||
isPlaying.value = false;
|
||||
currentVideoSource.value = '';
|
||||
videoStatus.value = '已停止播放';
|
||||
|
||||
const client = AuthManager.createAuthenticatedHdmiVideoStreamClient();
|
||||
client.disableHdmiTransmission();
|
||||
|
||||
addLog('info', '停止播放HDMI视频流');
|
||||
alert?.info('已停止播放HDMI视频流');
|
||||
}
|
||||
|
||||
// 处理视频加载错误
|
||||
function handleVideoError() {
|
||||
hasVideoError.value = true;
|
||||
videoStatus.value = '视频流加载失败';
|
||||
addLog('error', 'HDMI视频流加载失败');
|
||||
}
|
||||
|
||||
// 处理视频加载成功
|
||||
function handleVideoLoad() {
|
||||
hasVideoError.value = false;
|
||||
videoStatus.value = '视频流播放中';
|
||||
addLog('success', 'HDMI视频流加载成功');
|
||||
}
|
||||
|
||||
// 处理视频点击
|
||||
function handleVideoClick() {
|
||||
if (!isPlaying.value || hasVideoError.value || !endpoint.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 可以在这里添加点击视频的交互逻辑
|
||||
addLog('info', '视频画面被点击');
|
||||
}
|
||||
|
||||
// 重试连接
|
||||
function tryReconnect() {
|
||||
hasVideoError.value = false;
|
||||
if (endpoint.value) {
|
||||
startStream();
|
||||
}
|
||||
}
|
||||
|
||||
// 在新标签页打开视频
|
||||
function openInNewTab(url: string) {
|
||||
window.open(url, '_blank');
|
||||
addLog('info', '在新标签页打开HDMI视频页面');
|
||||
}
|
||||
|
||||
// 获取快照
|
||||
async function takeSnapshot() {
|
||||
if (!endpoint.value) {
|
||||
alert?.warn('请先刷新连接获取板卡信息');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
addLog('info', '正在获取HDMI视频快照...');
|
||||
|
||||
const response = await fetch(endpoint.value.snapshotUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache'
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const blob = await response.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `hdmi_snapshot_${new Date().toISOString().replace(/:/g, '-')}.jpg`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
|
||||
addLog('success', '快照下载成功');
|
||||
alert?.success('HDMI快照下载成功');
|
||||
} else {
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取HDMI快照失败:', error);
|
||||
addLog('error', `获取快照失败: ${error}`);
|
||||
alert?.error('获取HDMI快照失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 复制到剪贴板
|
||||
async function copyToClipboard(text: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
addLog('success', '地址已复制到剪贴板');
|
||||
alert?.success('地址已复制到剪贴板');
|
||||
} catch (error) {
|
||||
console.error('复制到剪贴板失败:', error);
|
||||
addLog('error', '复制到剪贴板失败');
|
||||
alert?.error('复制到剪贴板失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 组件挂载时初始化
|
||||
onMounted(() => {
|
||||
addLog('info', 'HDMI视频流界面已初始化');
|
||||
refreshEndpoint();
|
||||
});
|
||||
|
||||
// 组件卸载时清理
|
||||
onUnmounted(() => {
|
||||
stopStream();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 对焦动画效果 */
|
||||
@keyframes focus-pulse {
|
||||
0%, 100% {
|
||||
box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
|
||||
}
|
||||
50% {
|
||||
box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
|
||||
}
|
||||
}
|
||||
|
||||
.focus-animation {
|
||||
animation: focus-pulse 1s ease-out;
|
||||
}
|
||||
</style>
|
||||
@@ -61,13 +61,6 @@
|
||||
<Settings class="w-5 h-5" />
|
||||
触发设置
|
||||
</div>
|
||||
<!-- 配置摘要 -->
|
||||
<div class="flex items-center gap-4 text-sm text-gray-500">
|
||||
<span>{{ analyzer.enabledChannelCount.value }}/32 通道</span>
|
||||
<span>捕获: {{ analyzer.captureLength.value }}</span>
|
||||
<span>预捕获: {{ analyzer.preCaptureLength.value }}</span>
|
||||
<span>{{ analyzer.globalModes.find(m => m.value === analyzer.currentGlobalMode.value)?.label || '未知' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<!-- 状态指示 -->
|
||||
|
||||
Reference in New Issue
Block a user