using System.ComponentModel;
using Dabit.Mcp.Services;
using DibdProtocol.Protocol;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Server;
namespace Dabit.Mcp.Tools;
/// 밝기·전원 설정 도구. ⚠️ 쓰기.
[McpServerToolType]
public sealed class BrightnessPowerTools
{
private readonly LedControlService _led;
private readonly ILogger _log;
public BrightnessPowerTools(LedControlService led, ILogger log)
{
_led = led;
_log = log;
}
// 밝기 단계 0~4 → (표시%, HEX byte). 정본 SettingsViewModel 매핑 그대로(byte-identical).
private static readonly (int Pct, byte Hex)[] BrightnessMap =
{
(100, 0x64), (75, 0x48), (50, 0x32), (25, 0x19), (5, 0x05),
};
[McpServerTool]
[Description("전광판 밝기를 설정한다. ⚠️ 쓰기·설정 저장. level 0~4: 0=100%, 1=75%, 2=50%, 3=25%, 4=5%.")]
public async Task SetBrightness(
[Description("밝기 단계 0~4 (0=100% 1=75% 2=50% 3=25% 4=5%)")] int level,
CancellationToken ct = default)
{
if (level < 0 || level > 4)
return "밝기 단계는 0~4여야 합니다 (0=100% 1=75% 2=50% 3=25% 4=5%).";
var (pct, hex) = BrightnessMap[level];
var resp = await _led.SendHexAsync(HexCommand.SetBrightness, new[] { hex }, ct, 5000);
var (ok, msg) = LedControlService.CheckWriteStatus(HexCommand.SetBrightness, resp);
return ok ? $"밝기 {pct}% 설정." : $"밝기 설정 실패 — {msg}";
}
[McpServerTool]
[Description("전광판 LED 전원을 켠다. ⚠️ 쓰기.")]
public async Task LedPowerOn(CancellationToken ct = default)
{
var resp = await _led.SendHexAsync(HexCommand.LedPowerControl, new byte[] { 0x01 }, ct);
var (ok, msg) = LedControlService.CheckWriteStatus(HexCommand.LedPowerControl, resp);
return ok ? "LED 전원 켜짐." : $"전원 켜기 실패 — {msg}";
}
[McpServerTool]
[Description("전광판 LED 전원을 끈다. ⚠️ 쓰기 — 화면이 꺼진다.")]
public async Task LedPowerOff(CancellationToken ct = default)
{
var resp = await _led.SendHexAsync(HexCommand.LedPowerControl, new byte[] { 0x00 }, ct);
var (ok, msg) = LedControlService.CheckWriteStatus(HexCommand.LedPowerControl, resp);
return ok ? "LED 전원 꺼짐." : $"전원 끄기 실패 — {msg}";
}
}