Initial commit

This commit is contained in:
2026-07-03 16:31:37 +07:00
commit 899c7c637d
1939 changed files with 641750 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
using RobotNet10.CANOpen.Enums;
using RobotNet10.CANOpen.Interfaces;
using RobotNet10.CANOpen.Models;
namespace RobotNet10.CANOpen.Services;
public class NmtMaster
{
private readonly ICanBus _canBus;
public NmtMaster(ICanBus canBus)
{
_canBus = canBus;
}
public async Task SendCommandAsync(NmtCommand command, byte nodeId, CancellationToken cancellationToken = default)
{
var message = new NmtMessage(command, nodeId);
await _canBus.SendFrameAsync((uint)CanMessageType.Nmt, message.ToBytes(), cancellationToken);
}
public async Task BroadcastCommandAsync(NmtCommand command, CancellationToken cancellationToken = default)
{
await SendCommandAsync(command, 0, cancellationToken);
}
public async Task StartNodeAsync(byte nodeId, CancellationToken cancellationToken = default)
{
await SendCommandAsync(NmtCommand.Start, nodeId, cancellationToken);
}
public async Task StopNodeAsync(byte nodeId, CancellationToken cancellationToken = default)
{
await SendCommandAsync(NmtCommand.Stop, nodeId, cancellationToken);
}
public async Task SetPreOperationalAsync(byte nodeId, CancellationToken cancellationToken = default)
{
await SendCommandAsync(NmtCommand.PreOperational, nodeId, cancellationToken);
}
public async Task ResetNodeAsync(byte nodeId, CancellationToken cancellationToken = default)
{
await SendCommandAsync(NmtCommand.ResetNode, nodeId, cancellationToken);
}
public async Task ResetCommunicationAsync(byte nodeId, CancellationToken cancellationToken = default)
{
await SendCommandAsync(NmtCommand.ResetCommunication, nodeId, cancellationToken);
}
}