save
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
@page "/robot-state"
|
||||
@using RobotApp.Client.Services
|
||||
@using RobotApp.VDA5050.State
|
||||
@rendermode InteractiveWebAssemblyNoPrerender
|
||||
|
||||
@inject StateMsg RobotState
|
||||
@inject RobotStateClient RobotStateClient
|
||||
@implements IDisposable
|
||||
@rendermode InteractiveWebAssembly
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.False" Class="pa-4">
|
||||
<!-- ===================================================== -->
|
||||
@@ -11,34 +12,46 @@
|
||||
<MudPaper Class="pa-6 mb-4 d-flex align-center justify-space-between" Elevation="3">
|
||||
<div>
|
||||
<MudText Typo="Typo.h4">🤖 VDA 5050 Robot Dashboard</MudText>
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">
|
||||
@RobotState.Version •
|
||||
@RobotState.Manufacturer
|
||||
@RobotState.SerialNumber
|
||||
</MudText>
|
||||
@if (CurrentState != null)
|
||||
{
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">
|
||||
@CurrentState.Version •
|
||||
@CurrentState.Manufacturer •
|
||||
@CurrentState.SerialNumber
|
||||
</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">
|
||||
Connecting to robot...
|
||||
</MudText>
|
||||
}
|
||||
</div>
|
||||
@* @if (RobotState.Current != null)
|
||||
|
||||
@if (CurrentState != null)
|
||||
{
|
||||
<MudChip T="string" Size="Size.Large"
|
||||
Color="@(RobotState.Current ? Color.Success : Color.Error)">
|
||||
@(RobotState.Current.IsOnline ? "ONLINE" : "OFFLINE")
|
||||
Color="@(IsConnected ? Color.Success : Color.Error)"
|
||||
Variant="Variant.Filled">
|
||||
@(IsConnected ? "ONLINE" : "OFFLINE")
|
||||
</MudChip>
|
||||
} *@
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
@if (RobotState == null)
|
||||
@if (CurrentState == null)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
|
||||
Waiting for robot state (VDA5050)...
|
||||
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined" Class="mb-4">
|
||||
<MudAlertTitle>Waiting for robot state data...</MudAlertTitle>
|
||||
Connecting to SignalR hub and subscribing to robot updates.
|
||||
<MudProgressLinear Indeterminate Class="mt-3" />
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
var msg = RobotState;
|
||||
var msg = CurrentState;
|
||||
|
||||
<!-- ===================================================== -->
|
||||
<!-- 📨 MESSAGE META (DEBUG / TRACE) -->
|
||||
<!-- MESSAGE META -->
|
||||
<!-- ===================================================== -->
|
||||
<MudPaper Class="pa-3 mb-4" Elevation="1">
|
||||
<MudGrid Spacing="2">
|
||||
@@ -56,9 +69,7 @@
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="2">
|
||||
<MudText Typo="Typo.caption">OrderUpdateId</MudText>
|
||||
<MudChip T="string" Color="Color.Primary">
|
||||
@msg.OrderUpdateId
|
||||
</MudChip>
|
||||
<MudChip T="string" Color="Color.Primary">@msg.OrderUpdateId</MudChip>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudPaper>
|
||||
@@ -104,7 +115,7 @@
|
||||
</MudItem>
|
||||
<MudItem xs="6" Class="d-flex justify-end">
|
||||
<MudText Typo="Typo.caption">
|
||||
DeviationRange: <b>@msg.AgvPosition.DeviationRange</b>
|
||||
Deviation: <b>@msg.AgvPosition.DeviationRange</b>
|
||||
</MudText>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
@@ -141,7 +152,7 @@
|
||||
<MudText><b>@msg.BatteryState.BatteryVoltage.ToString("F1")</b> V</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="4">
|
||||
<MudText Typo="Typo.caption">Health</MudText>
|
||||
<MudText Typo="Typo.caption">Health (SOH)</MudText>
|
||||
<MudText><b>@msg.BatteryState.BatteryHealth</b> %</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="4">
|
||||
@@ -164,16 +175,14 @@
|
||||
Last Node: <b>@msg.LastNodeId</b>
|
||||
<MudText Typo="Typo.caption" Inline="true">Seq: @msg.LastNodeSequenceId</MudText>
|
||||
</MudText>
|
||||
<MudText>Distance: @msg.DistanceSinceLastNode:F1 m</MudText>
|
||||
<MudText>Distance since last node: @msg.DistanceSinceLastNode:F1 m</MudText>
|
||||
<MudDivider Class="my-3" />
|
||||
|
||||
@{
|
||||
var nodeReleased = msg.NodeStates?.Count(n => n.Released) ?? 0;
|
||||
var nodeTotal = msg.NodeStates?.Length ?? 0;
|
||||
var edgeReleased = msg.EdgeStates?.Count(e => e.Released) ?? 0;
|
||||
var edgeTotal = msg.EdgeStates?.Length ?? 0;
|
||||
}
|
||||
|
||||
<div class="d-flex align-center flex-wrap gap-2">
|
||||
<MudChip T="string" Color="Color.Info">Nodes: @nodeReleased / @nodeTotal</MudChip>
|
||||
<MudChip T="string" Color="Color.Info">Edges: @edgeReleased / @edgeTotal</MudChip>
|
||||
@@ -190,175 +199,89 @@
|
||||
<!-- ERRORS + INFORMATION -->
|
||||
<MudItem xs="12" md="12" lg="6">
|
||||
<MudPaper Class="pa-5 h-100" Elevation="2">
|
||||
|
||||
<MudText Typo="Typo.h6">🚨 Errors & Information</MudText>
|
||||
<MudDivider Class="my-3" />
|
||||
|
||||
@{
|
||||
var rows = new List<MessageRow>();
|
||||
|
||||
if (msg.Errors != null)
|
||||
{
|
||||
foreach (var err in msg.Errors)
|
||||
{
|
||||
rows.Add(new MessageRow(
|
||||
err.ErrorType ?? "-",
|
||||
err.ErrorLevel ?? "-",
|
||||
err.ErrorDescription ?? "",
|
||||
true
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if (msg.Information != null)
|
||||
{
|
||||
foreach (var info in msg.Information)
|
||||
{
|
||||
rows.Add(new MessageRow(
|
||||
info.InfoType ?? "-",
|
||||
info.InfoLevel ?? "-",
|
||||
info.InfoDescription ?? "",
|
||||
false
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
var sortedMessages = rows
|
||||
.OrderBy(r => r.IsError ? 0 : 1) // Errors trước
|
||||
.ThenBy(r => r.Type)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
<MudTable Items="@sortedMessages"
|
||||
<MudTable Items="@MessageRows"
|
||||
Dense="true"
|
||||
Hover="true"
|
||||
Bordered="true"
|
||||
Elevation="0"
|
||||
Height="180px"
|
||||
Breakpoint="Breakpoint.Sm"
|
||||
HorizontalScrollbar="true">
|
||||
|
||||
Height="200px"
|
||||
FixedHeader="true">
|
||||
<ColGroup>
|
||||
<col style="width: 35%" />
|
||||
<col style="width: 20%" />
|
||||
<col />
|
||||
</ColGroup>
|
||||
|
||||
<HeaderContent>
|
||||
<MudTh>Type</MudTh>
|
||||
<MudTh>Level</MudTh>
|
||||
<MudTh>Description</MudTh>
|
||||
</HeaderContent>
|
||||
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Type">
|
||||
<MudTd>
|
||||
<MudText Class="@(context.IsError ? "text-error" : "text-info")">
|
||||
<b>@context.Type</b>
|
||||
</MudText>
|
||||
</MudTd>
|
||||
|
||||
<MudTd DataLabel="Level">
|
||||
<MudChip T="string"
|
||||
Size="Size.Small"
|
||||
Color="@(context.Level == "ERROR"
|
||||
? Color.Error
|
||||
: context.Level == "WARNING"
|
||||
? Color.Warning
|
||||
: Color.Info)">
|
||||
@context.Level
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
|
||||
<MudTd DataLabel="Description">
|
||||
<MudText Typo="Typo.caption"
|
||||
Class="text-truncate"
|
||||
Title="@context.Description">
|
||||
<MudTd>
|
||||
<MudChip T="string" Size="Size.Small"
|
||||
Color="@(context.Level.Contains("ERROR", StringComparison.OrdinalIgnoreCase) ? Color.Error :
|
||||
context.Level.Contains("WARN", StringComparison.OrdinalIgnoreCase) ? Color.Warning :
|
||||
Color.Info)">
|
||||
@context.Level
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
<MudTd>
|
||||
<MudText Typo="Typo.caption" Class="text-truncate" Title="@context.Description">
|
||||
@context.Description
|
||||
</MudText>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
|
||||
<NoRecordsContent>
|
||||
<MudText Typo="Typo.caption"
|
||||
Color="Color.Secondary"
|
||||
Class="pa-4 text-center">
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="pa-4 text-center">
|
||||
No errors or information messages
|
||||
</MudText>
|
||||
</NoRecordsContent>
|
||||
|
||||
</MudTable>
|
||||
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
|
||||
<!-- ACTIONS -->
|
||||
<MudItem xs="12" md="6" lg="3">
|
||||
<MudPaper Class="pa-5 h-100" Elevation="2">
|
||||
|
||||
<MudText Typo="Typo.h6">⚙️ Actions</MudText>
|
||||
<MudDivider Class="my-3" />
|
||||
|
||||
<MudTable Items="msg.ActionStates"
|
||||
Dense="true"
|
||||
Dense="true"
|
||||
Hover="true"
|
||||
Bordered="true"
|
||||
Elevation="0"
|
||||
Height="160px"
|
||||
Breakpoint="Breakpoint.Sm"
|
||||
HorizontalScrollbar="true"
|
||||
Height="180px"
|
||||
FixedHeader="true">
|
||||
|
||||
<ColGroup>
|
||||
<col style="width: 40%" />
|
||||
<col style="width: 35%" />
|
||||
<col style="width: 25%" />
|
||||
</ColGroup>
|
||||
|
||||
<HeaderContent>
|
||||
<MudTh>Action</MudTh>
|
||||
<MudTh>Action ID</MudTh>
|
||||
<MudTh class="text-right">Status</MudTh>
|
||||
</HeaderContent>
|
||||
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Action">
|
||||
<MudText Typo="Typo.body2"
|
||||
Class="text-truncate"
|
||||
Title="@context.ActionType">
|
||||
@context.ActionType
|
||||
</MudText>
|
||||
<MudTd><MudText Typo="Typo.body2" Class="text-truncate" Title="@context.ActionType">@context.ActionType</MudText></MudTd>
|
||||
<MudTd><MudText Typo="Typo.caption">@context.ActionId</MudText></MudTd>
|
||||
<MudTd Class="text-right">
|
||||
<MudChip T="string" Size="Size.Small"
|
||||
Color="@(context.ActionStatus == "RUNNING" ? Color.Info :
|
||||
context.ActionStatus == "FINISHED" ? Color.Success :
|
||||
context.ActionStatus == "FAILED" ? Color.Error : Color.Default)">
|
||||
@context.ActionStatus
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
|
||||
<MudTd DataLabel="Action ID">
|
||||
<MudText Typo="Typo.caption">
|
||||
@context.ActionId
|
||||
</MudText>
|
||||
</MudTd>
|
||||
|
||||
<MudTd DataLabel="Status" Class="text-right">
|
||||
<MudChip T="string"
|
||||
Size="Size.Small"
|
||||
Variant="Variant.Filled"
|
||||
Color="@(context.ActionStatus == "RUNNING"
|
||||
? Color.Info
|
||||
: context.ActionStatus == "FINISHED"
|
||||
? Color.Success
|
||||
: Color.Error)">
|
||||
@context.ActionStatus
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
|
||||
</RowTemplate>
|
||||
<NoRecordsContent>
|
||||
<MudText Typo="Typo.caption"
|
||||
Color="Color.Secondary"
|
||||
Class="pa-4 text-center">
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="pa-4 text-center">
|
||||
No active actions
|
||||
</MudText>
|
||||
</NoRecordsContent>
|
||||
|
||||
</MudTable>
|
||||
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
@@ -377,21 +300,75 @@
|
||||
</MudChip>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
</MudGrid>
|
||||
}
|
||||
</MudContainer>
|
||||
|
||||
@code {
|
||||
private StateMsg? CurrentState;
|
||||
private bool IsConnected => RobotStateClient.LatestStates.ContainsKey(RobotSerial);
|
||||
|
||||
private async Task OnStateChanged()
|
||||
=> await InvokeAsync(StateHasChanged);
|
||||
// Thay bằng serial number thật của robot bạn muốn theo dõi
|
||||
private readonly string RobotSerial = "T800-002";
|
||||
|
||||
private List<MessageRow> MessageRows = new();
|
||||
|
||||
private record MessageRow(
|
||||
string Type,
|
||||
string Level,
|
||||
string Description,
|
||||
bool IsError
|
||||
);
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// Subscribe sự kiện nhận state
|
||||
RobotStateClient.OnStateReceived += OnRobotStateReceived;
|
||||
|
||||
// Bắt đầu kết nối SignalR (nếu chưa)
|
||||
if (RobotStateClient.LatestStates.Count == 0)
|
||||
{
|
||||
await RobotStateClient.StartAsync();
|
||||
}
|
||||
|
||||
// Đăng ký theo dõi robot cụ thể
|
||||
await RobotStateClient.SubscribeRobotAsync(RobotSerial);
|
||||
|
||||
// Lấy state hiện tại nếu đã có
|
||||
CurrentState = RobotStateClient.GetLatestState(RobotSerial);
|
||||
UpdateMessageRows();
|
||||
}
|
||||
|
||||
private void OnRobotStateReceived(string serialNumber, StateMsg state)
|
||||
{
|
||||
if (serialNumber != RobotSerial) return;
|
||||
|
||||
InvokeAsync(() =>
|
||||
{
|
||||
CurrentState = state;
|
||||
UpdateMessageRows();
|
||||
StateHasChanged();
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateMessageRows()
|
||||
{
|
||||
MessageRows.Clear();
|
||||
|
||||
if (CurrentState?.Errors != null)
|
||||
{
|
||||
foreach (var err in CurrentState.Errors)
|
||||
{
|
||||
MessageRows.Add(new MessageRow(err.ErrorType ?? "-", err.ErrorLevel ?? "ERROR", err.ErrorDescription ?? "", true));
|
||||
}
|
||||
}
|
||||
|
||||
if (CurrentState?.Information != null)
|
||||
{
|
||||
foreach (var info in CurrentState.Information)
|
||||
{
|
||||
MessageRows.Add(new MessageRow(info.InfoType ?? "-", info.InfoLevel ?? "INFO", info.InfoDescription ?? "", false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
RobotStateClient.OnStateReceived -= OnRobotStateReceived;
|
||||
}
|
||||
|
||||
private record MessageRow(string Type, string Level, string Description, bool IsError);
|
||||
}
|
||||
Reference in New Issue
Block a user