- refactor: DabitChe.Mcp → Dabit.Mcp (namespace, csproj, exe 모두) - fix: display_message colors를 쉼표 구분 문자열로 변경 (ModelContextProtocol 1.3.0 배열 바인딩 버그 우회) - docs: scroll 4방향(left/right/up/down) 실기 검증 완료 (DIBD600T V3.6.1) 20 도구 (읽기 4 + 콘텐츠 2 + 설정 14), stdio 전송, Windows exe. 실기 검증: scroll/fill_screen 8색/display_message 글자별색 모두 정상. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
60 lines
2.5 KiB
C#
60 lines
2.5 KiB
C#
using System.ComponentModel;
|
|
using Dabit.Mcp.Services;
|
|
using DibdProtocol.Protocol;
|
|
using Microsoft.Extensions.Logging;
|
|
using ModelContextProtocol.Server;
|
|
|
|
namespace Dabit.Mcp.Tools;
|
|
|
|
/// <summary>밝기·전원 설정 도구. ⚠️ 쓰기.</summary>
|
|
[McpServerToolType]
|
|
public sealed class BrightnessPowerTools
|
|
{
|
|
private readonly LedControlService _led;
|
|
private readonly ILogger<BrightnessPowerTools> _log;
|
|
|
|
public BrightnessPowerTools(LedControlService led, ILogger<BrightnessPowerTools> 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<string> 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<string> 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<string> 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}";
|
|
}
|
|
}
|