using Microsoft.Extensions.Logging; using Seyounth.Hyosung.Core.Agv.HikModels; using Seyounth.Hyosung.Data.Entities; using Seyounth.Hyosung.Data.Services; namespace Seyounth.Hyosung.Core.Agv; public class HyosungAgvService( ILoggerFactory loggerFactory, IAgvBinService agvBinService, ITrayService trayService, IDictService dictService) : IHyosungAgvService { private readonly HikAgv _agv = new(loggerFactory.CreateLogger()); public async Task StorageAsync(string trayCode) { AgvStatusInfo? status; do { status = await _agv.GetAgvStatus("BB", "4083"); await Task.Delay(1000); } while (status is null); var tray = await trayService.GetByCode(trayCode); var height = (int)Math.Ceiling((double)((tray.StackHeight ?? 0) / 10.0)!); var bin = await agvBinService.GetAvailableBin(height); AgvPosition start = new AgvPosition() { PositionCode = "A1", Type = "00" }; var stop = new AgvPosition() { PositionCode = bin.CtnrCode, Type = "05" }; if (!string.IsNullOrEmpty(bin.HeightCode)) await UnBin(bin); var ctnrType = await dictService.GetKeyAsync("AgvRackType", bin.Height.ToString()); if (string.IsNullOrEmpty(ctnrType)) ctnrType = "14"; bin.HeightCode = ctnrType; var taskCode = await _agv.CarryToAsync(start, stop, ctnrType, 120, "1"); await _agv.WaitingForTaskCompletedAsync(taskCode); await agvBinService.BindAsync(bin); } public async Task UnBin(AgvBinEntity bin) { await _agv.UnBin(bin); } }