From 7d3ef598de7e158ac2ba53cbff18d3806b3c496b Mon Sep 17 00:00:00 2001
From: SikongJueluo <1822250894@qq.com>
Date: Fri, 22 Aug 2025 02:17:30 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=A4=BA=E6=B3=A2?=
=?UTF-8?q?=E5=99=A8=E4=BF=AE=E6=94=B9=E5=90=8E=E6=97=A0=E6=B3=95=E9=85=8D?=
=?UTF-8?q?=E7=BD=AE=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?=E6=97=A0=E6=B3=95=E7=94=9F=E6=88=90api=E7=9A=84=E9=97=AE?=
=?UTF-8?q?=E9=A2=98=EF=BC=9Bfeat:=20=E6=96=B0=E5=A2=9E=E5=85=A8=E5=B1=80?=
=?UTF-8?q?=E6=8E=A7=E5=88=B6=E4=B8=83=E6=AE=B5=E6=95=B0=E7=A0=81=E7=AE=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
server/Program.cs | 2 +-
server/src/Peripherals/OscilloscopeClient.cs | 2 +-
server/src/Peripherals/WS2812Client.cs | 18 ++---
.../Oscilloscope/OscilloscopeManager.ts | 1 +
src/components/equipments/MotherBoardCaps.vue | 20 +++++-
.../SevenSegmentDisplayUltimate.vue | 65 ++++++++++---------
src/stores/equipments.ts | 2 +
src/utils/signalR/Database.ts | 8 +++
src/utils/signalR/Peripherals.WS2812Client.ts | 14 ++++
.../signalR/TypedSignalR.Client/index.ts | 57 +++++++++++++++-
.../TypedSignalR.Client/server.Hubs.ts | 21 ++++++
src/utils/signalR/server.Hubs.ts | 6 ++
src/views/Project/Oscilloscope.vue | 46 ++++++++-----
13 files changed, 204 insertions(+), 58 deletions(-)
create mode 100644 src/utils/signalR/Database.ts
create mode 100644 src/utils/signalR/Peripherals.WS2812Client.ts
diff --git a/server/Program.cs b/server/Program.cs
index 43e4cd1..e525c32 100644
--- a/server/Program.cs
+++ b/server/Program.cs
@@ -130,7 +130,7 @@ try
.AllowAnyHeader()
);
options.AddPolicy("SignalR", policy => policy
- .WithOrigins("http://localhost:5173")
+ .WithOrigins([$"http://{Global.LocalHost}:5173", "http://127.0.0.1:5173"])
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
diff --git a/server/src/Peripherals/OscilloscopeClient.cs b/server/src/Peripherals/OscilloscopeClient.cs
index 9d092a5..2cff2cf 100644
--- a/server/src/Peripherals/OscilloscopeClient.cs
+++ b/server/src/Peripherals/OscilloscopeClient.cs
@@ -362,7 +362,7 @@ class OscilloscopeCtrl
{
// 等待WAVE_READY[0]位为1,最多等待50ms(5次x10ms间隔)
var readyResult = await UDPClientPool.ReadAddrWithWait(
- this.ep, this.taskID, OscilloscopeAddr.WAVE_READY, 0b00, 0x01, 10, 50);
+ this.ep, this.taskID, OscilloscopeAddr.WAVE_READY, 0b01, 0x01, 10, 50);
if (!readyResult.IsSuccessful)
{
diff --git a/server/src/Peripherals/WS2812Client.cs b/server/src/Peripherals/WS2812Client.cs
index 38a3190..f27c1e4 100644
--- a/server/src/Peripherals/WS2812Client.cs
+++ b/server/src/Peripherals/WS2812Client.cs
@@ -1,5 +1,6 @@
using System.Net;
using DotNext;
+using Tapper;
namespace Peripherals.WS2812Client;
@@ -12,7 +13,8 @@ class WS2812Addr
///
/// RGB颜色结构体,包含红、绿、蓝三个颜色分量
///
-public struct RGBColor
+[TranspilationSource]
+public class RGBColor
{
public byte Red { get; set; }
public byte Green { get; set; }
@@ -84,13 +86,13 @@ public class WS2812Client
{
if (ledIndex < 0 || ledIndex >= WS2812Addr.LED_COUNT)
{
- return new(new ArgumentOutOfRangeException(nameof(ledIndex),
+ return new(new ArgumentOutOfRangeException(nameof(ledIndex),
$"LED index must be between 0 and {WS2812Addr.LED_COUNT - 1}"));
}
if (MsgBus.IsRunning)
MsgBus.UDPServer.ClearUDPData(this.address, this.taskID);
- else
+ else
return new(new Exception("Message Bus not work!"));
var addr = WS2812Addr.BASE + (UInt32)(ledIndex * 4); // 每个地址32位,步长为4字节
@@ -123,14 +125,14 @@ public class WS2812Client
{
if (MsgBus.IsRunning)
MsgBus.UDPServer.ClearUDPData(this.address, this.taskID);
- else
+ else
return new(new Exception("Message Bus not work!"));
try
{
// 一次性读取所有LED数据,每个LED占用4字节,总共128*4=512字节
var ret = await UDPClientPool.ReadAddr4Bytes(this.ep, this.taskID, WS2812Addr.BASE, WS2812Addr.LED_COUNT, this.timeout);
-
+
if (!ret.IsSuccessful)
{
logger.Error($"Get all LED colors failed: {ret.Error}");
@@ -139,7 +141,7 @@ public class WS2812Client
var data = ret.Value;
var expectedLength = WS2812Addr.LED_COUNT * 4; // 128 * 4 = 512 bytes
-
+
if (data.Length < expectedLength)
{
var error = new Exception($"Invalid data length: expected {expectedLength} bytes, got {data.Length}");
@@ -148,7 +150,7 @@ public class WS2812Client
}
var colors = new RGBColor[WS2812Addr.LED_COUNT];
-
+
for (int i = 0; i < WS2812Addr.LED_COUNT; i++)
{
var offset = i * 4;
@@ -156,7 +158,7 @@ public class WS2812Client
var colorData = BitConverter.ToUInt32(data, offset);
colors[i] = RGBColor.FromUInt32(colorData);
}
-
+
return new(colors);
}
catch (Exception ex)
diff --git a/src/components/Oscilloscope/OscilloscopeManager.ts b/src/components/Oscilloscope/OscilloscopeManager.ts
index c932ad2..d63abf4 100644
--- a/src/components/Oscilloscope/OscilloscopeManager.ts
+++ b/src/components/Oscilloscope/OscilloscopeManager.ts
@@ -156,6 +156,7 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(
try {
const proxy = getHubProxy();
+ // console.log("Applying configuration", config);
const success = await proxy.initialize(config);
if (success) {
diff --git a/src/components/equipments/MotherBoardCaps.vue b/src/components/equipments/MotherBoardCaps.vue
index 6b95528..9a5c62e 100644
--- a/src/components/equipments/MotherBoardCaps.vue
+++ b/src/components/equipments/MotherBoardCaps.vue
@@ -66,7 +66,7 @@
外设
-
@@ -146,6 +155,15 @@ async function handleMatrixkeyCheckboxChange(event: Event) {
}
}
+async function handleSevenSegmentDisplayCheckboxChange(event: Event) {
+ const target = event.target as HTMLInputElement;
+ if (target.checked) {
+ await eqps.sevenSegmentDisplaySetOnOff(true);
+ } else {
+ await eqps.sevenSegmentDisplaySetOnOff(false);
+ }
+}
+
async function toggleJtagBoundaryScan() {
eqps.jtagBoundaryScanSetOnOff(!eqps.enableJtagBoundaryScan);
}
diff --git a/src/components/equipments/SevenSegmentDisplayUltimate.vue b/src/components/equipments/SevenSegmentDisplayUltimate.vue
index 586d442..ce39a80 100644
--- a/src/components/equipments/SevenSegmentDisplayUltimate.vue
+++ b/src/components/equipments/SevenSegmentDisplayUltimate.vue
@@ -41,7 +41,7 @@
(), {
size: 1,
color: "red",
- enableDigitalTwin: false,
+ // enableDigitalTwin: false,
digitalTwinNum: 1,
afterglowDuration: 500,
cathodeType: "common",
@@ -158,7 +164,7 @@ function isBitSet(byte: number, bit: number): boolean {
}
function isSegmentActive(segmentId: keyof typeof SEGMENT_BITS): boolean {
- if (props.enableDigitalTwin) {
+ if (eqps.enableSevenSegmentDisplay) {
// 数字孪生模式:余晖优先,然后是当前byte
const bit = SEGMENT_BITS[segmentId];
return (
@@ -174,18 +180,16 @@ function isSegmentActive(segmentId: keyof typeof SEGMENT_BITS): boolean {
// SignalR数字孪生集成
// ============================================================================
-const eqps = useEquipments();
-
async function initDigitalTwin() {
if (
- !props.enableDigitalTwin ||
+ !eqps.enableSevenSegmentDisplay ||
props.digitalTwinNum <= 0 ||
props.digitalTwinNum > 31
)
return;
try {
- eqps.sevenSegmentDisplaySetOnOff(props.enableDigitalTwin);
+ eqps.sevenSegmentDisplaySetOnOff(eqps.enableSevenSegmentDisplay);
console.log(
`Digital twin initialized for address: ${props.digitalTwinNum}`,
@@ -205,7 +209,9 @@ watch(
)
return;
- handleDigitalTwinData(eqps.sevenSegmentDisplayData[props.digitalTwinNum - 1]);
+ handleDigitalTwinData(
+ eqps.sevenSegmentDisplayData[props.digitalTwinNum - 1],
+ );
},
);
@@ -265,7 +271,7 @@ const { getConstraintState, onConstraintStateChange } = useConstraintsStore();
let constraintUnsubscribe: (() => void) | null = null;
function updateConstraintStates() {
- if (props.enableDigitalTwin) return; // 数字孪生模式下忽略约束
+ if (eqps.enableSevenSegmentDisplay) return; // 数字孪生模式下忽略约束
// 获取COM状态
const comPin = props.pins.find((p) => p.pinId === "COM");
@@ -328,7 +334,7 @@ const pinRefs = ref>({});
// ============================================================================
onMounted(async () => {
- if (props.enableDigitalTwin) {
+ if (eqps.enableSevenSegmentDisplay) {
await initDigitalTwin();
} else {
constraintUnsubscribe = onConstraintStateChange(updateConstraintStates);
@@ -349,25 +355,24 @@ onUnmounted(() => {
});
// 监听模式切换
-watch(
- () => [props.enableDigitalTwin],
- async () => {
- // 清理旧模式
- cleanupDigitalTwin();
- if (constraintUnsubscribe) {
- constraintUnsubscribe();
- constraintUnsubscribe = null;
- }
+// watch(
+// () => [eqps.enableSevenSegmentDisplay],
+// async () => {
+// // 清理旧模式
+// if (constraintUnsubscribe) {
+// constraintUnsubscribe();
+// constraintUnsubscribe = null;
+// }
- // 初始化新模式
- if (props.enableDigitalTwin) {
- await initDigitalTwin();
- } else {
- constraintUnsubscribe = onConstraintStateChange(updateConstraintStates);
- updateConstraintStates();
- }
- },
-);
+// // 初始化新模式
+// if (eqps.enableSevenSegmentDisplay) {
+// await initDigitalTwin();
+// } else {
+// constraintUnsubscribe = onConstraintStateChange(updateConstraintStates);
+// updateConstraintStates();
+// }
+// },
+// );