first commit
This commit is contained in:
@@ -169,6 +169,48 @@ public class CommandService
|
||||
return PostAsync($"/api/asrs/workflow/{op}", null, ct, "ASRS");
|
||||
}
|
||||
|
||||
// ── ASRS qua OPC UA (gateway) ─────────────────────────────────────────
|
||||
public Task AsrsOpcHomeAsync(CancellationToken ct = default)
|
||||
=> PostAsrsOpcAsync("Home", null, "/api/asrs/opc/home", null, ct);
|
||||
|
||||
public Task AsrsOpcRetrieveAsync(int column, int shelf, int conveyor, CancellationToken ct = default)
|
||||
=> PostAsrsOpcAsync("Retrieve", $"{column}.{shelf} → BT{conveyor}", "/api/asrs/opc/retrieve",
|
||||
new { Column = column, Shelf = shelf, Conveyor = conveyor }, ct);
|
||||
|
||||
public Task AsrsOpcStoreAsync(int column, int shelf, int conveyor, CancellationToken ct = default)
|
||||
=> PostAsrsOpcAsync("Store", $"BT{conveyor} → {column}.{shelf}", "/api/asrs/opc/store",
|
||||
new { Column = column, Shelf = shelf, Conveyor = conveyor }, ct);
|
||||
|
||||
public Task AsrsOpcStoreAnyAsync(int conveyor, CancellationToken ct = default)
|
||||
=> PostAsrsOpcAsync("StoreAny", $"BT{conveyor}", "/api/asrs/opc/store-any",
|
||||
new { Conveyor = conveyor }, ct);
|
||||
|
||||
public Task AsrsOpcMoveAsync(int fromColumn, int fromShelf, int toColumn, int toShelf, CancellationToken ct = default)
|
||||
=> PostAsrsOpcAsync("Move", $"{fromColumn}.{fromShelf} → {toColumn}.{toShelf}", "/api/asrs/opc/move",
|
||||
new { FromColumn = fromColumn, FromShelf = fromShelf, ToColumn = toColumn, ToShelf = toShelf }, ct);
|
||||
|
||||
private async Task PostAsrsOpcAsync(string command, string? @params, string url, object? body, CancellationToken ct)
|
||||
{
|
||||
_log.LogAsrsOpcCommand(command, @params);
|
||||
try
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, url);
|
||||
if (body != null)
|
||||
request.Content = JsonContent.Create(body);
|
||||
var resp = await _http.SendAsync(request, ct);
|
||||
if (resp.IsSuccessStatusCode) return;
|
||||
|
||||
string? error = null;
|
||||
try { error = (await resp.Content.ReadFromJsonAsync<ApiErrorBody>(cancellationToken: ct))?.Error; }
|
||||
catch { }
|
||||
_log.LogAsrsOpcRejected(command, error ?? $"HTTP {(int)resp.StatusCode}");
|
||||
}
|
||||
catch (OperationCanceledException) { throw; }
|
||||
catch (Exception ex) { _log.LogAsrsOpcRejected(command, ex.Message); }
|
||||
}
|
||||
|
||||
private sealed record ApiErrorBody(string? Error);
|
||||
|
||||
// ── Workflow ──────────────────────────────────────────────────────────
|
||||
public Task WorkflowX1AAsync(int times, int ng, CancellationToken ct = default)
|
||||
{
|
||||
|
||||
@@ -279,6 +279,16 @@ public class ScriptLogService : IDisposable
|
||||
if (!ok) _conveyorPending = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASRS qua OPC UA: chỉ log lệnh gửi và lỗi bị từ chối ngay (HTTP).
|
||||
/// Kết quả thực thi (hoàn thành / lỗi / timeout) đến qua notification "ASRS" từ server.
|
||||
/// </summary>
|
||||
public void LogAsrsOpcCommand(string command, string? @params = null)
|
||||
=> Push(Line(CInfo, "INFO", "ASRS", command, _lang.T("→ gửi", "→ sent"), @params));
|
||||
|
||||
public void LogAsrsOpcRejected(string command, string? error)
|
||||
=> Push(Line(CError, "ERR", "ASRS", command, _lang.T("✗ từ chối", "✗ rejected"), error));
|
||||
|
||||
// ── State handlers ────────────────────────────────────────────────────
|
||||
|
||||
private void OnImrChanged()
|
||||
|
||||
@@ -12,6 +12,7 @@ public class StateService : IAsyncDisposable
|
||||
public RobotStateDto Amr { get; private set; } = EmptyRobot;
|
||||
public ConveyorPushDto Conveyor { get; private set; } = EmptyConveyor;
|
||||
public AsrsPushDto Asrs { get; private set; } = EmptyAsrs;
|
||||
public AsrsOpcPushDto AsrsOpc { get; private set; } = EmptyAsrsOpc;
|
||||
public WorkflowStateDto Workflow { get; private set; } = EmptyWorkflow;
|
||||
public SystemStateDto System { get; private set; } = new(false, false);
|
||||
|
||||
@@ -24,6 +25,7 @@ public class StateService : IAsyncDisposable
|
||||
public event Action? AmrChanged;
|
||||
public event Action? ConveyorChanged;
|
||||
public event Action? AsrsChanged;
|
||||
public event Action? AsrsOpcChanged;
|
||||
public event Action? WorkflowChanged;
|
||||
public event Action? SystemChanged;
|
||||
public event Action? LockStateChanged;
|
||||
@@ -87,6 +89,12 @@ public class StateService : IAsyncDisposable
|
||||
AsrsChanged?.Invoke();
|
||||
});
|
||||
|
||||
_hub.On<AsrsOpcPushDto>(HubContracts.AsrsOpcStateEvent, dto =>
|
||||
{
|
||||
AsrsOpc = dto;
|
||||
AsrsOpcChanged?.Invoke();
|
||||
});
|
||||
|
||||
_hub.On<WorkflowStateDto>(HubContracts.WorkflowStateEvent, dto =>
|
||||
{
|
||||
Workflow = dto;
|
||||
@@ -142,6 +150,9 @@ public class StateService : IAsyncDisposable
|
||||
private static readonly AsrsPushDto EmptyAsrs =
|
||||
new(null, null, null, null, null, null, null, null, null, null, null, null, null, true, false, Array.Empty<string>(), null);
|
||||
|
||||
private static readonly AsrsOpcPushDto EmptyAsrsOpc =
|
||||
new(false, false, null, null, null, null, new bool?[AsrsOpcLayout.SlotCount], false, null, null);
|
||||
|
||||
private static readonly WorkflowStateDto EmptyWorkflow =
|
||||
new(false, null, 0, "", "", false, null, null, false, null, null, null, null, false, null, null, null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user