Initial commit

This commit is contained in:
2026-07-13 09:25:40 +07:00
parent c08ff54676
commit bccfb156d7
1938 changed files with 641646 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
using RobotNet10.CANOpen.Enums;
namespace RobotNet10.CANOpen.Models;
public readonly struct NmtMessage(NmtCommand command, byte nodeId)
{
public NmtCommand Command { get; init; } = command;
public byte NodeId { get; init; } = nodeId;
public byte[] ToBytes()
{
return [(byte)Command, NodeId];
}
public static NmtMessage FromBytes(byte[] data)
{
if (data.Length < 2)
throw new ArgumentException("NMT message must be at least 2 bytes");
return new NmtMessage
{
Command = (NmtCommand)data[0],
NodeId = data[1]
};
}
}
public readonly struct HeartbeatMessage(byte nodeId, NmtState state)
{
public byte NodeId { get; init; } = nodeId;
public NmtState State { get; init; } = state;
public byte[] ToBytes()
{
return [(byte)State];
}
public static HeartbeatMessage FromBytes(uint canId, byte[] data)
{
if (data.Length < 1)
throw new ArgumentException("Heartbeat message must be at least 1 byte");
byte nodeId = (byte)(canId & 0x7F);
return new HeartbeatMessage
{
NodeId = nodeId,
State = (NmtState)data[0]
};
}
}