using RobotNet10.CANOpen.Enums; using RobotNet10.CANOpen.Models; using RobotNet10.CANOpen.Services; namespace RobotNet10.CANOpen.Interfaces; public interface ICanOpenDevice { byte NodeId { get; } NmtState State { get; } /// /// PDO Manager để quản lý PDOs /// PdoManager Pdo { get; } // Events event EventHandler? PdoReceived; event EventHandler? EmergencyReceived; event EventHandler? HeartbeatReceived; event EventHandler? HeartbeatTimeout; // SDO Operations Task ReadObjectAsync(ushort index, byte subIndex, CancellationToken cancellationToken = default); Task WriteObjectAsync(ushort index, byte subIndex, byte[] data, CancellationToken cancellationToken = default); // Helper methods for reading Task ReadUInt8Async(ushort index, byte subIndex, CancellationToken cancellationToken = default); Task ReadUInt16Async(ushort index, byte subIndex, CancellationToken cancellationToken = default); Task ReadUInt32Async(ushort index, byte subIndex, CancellationToken cancellationToken = default); Task ReadInt16Async(ushort index, byte subIndex, CancellationToken cancellationToken = default); Task ReadInt32Async(ushort index, byte subIndex, CancellationToken cancellationToken = default); // Helper methods for writing Task WriteUInt8Async(ushort index, byte subIndex, byte value, CancellationToken cancellationToken = default); Task WriteUInt16Async(ushort index, byte subIndex, ushort value, CancellationToken cancellationToken = default); Task WriteUInt32Async(ushort index, byte subIndex, uint value, CancellationToken cancellationToken = default); Task WriteInt16Async(ushort index, byte subIndex, short value, CancellationToken cancellationToken = default); Task WriteInt32Async(ushort index, byte subIndex, int value, CancellationToken cancellationToken = default); // NMT Operations Task SendNmtCommandAsync(NmtCommand command, CancellationToken cancellationToken = default); Task StartNodeAsync(CancellationToken cancellationToken = default); Task StopNodeAsync(CancellationToken cancellationToken = default); Task ResetNodeAsync(CancellationToken cancellationToken = default); Task ResetCommunicationAsync(CancellationToken cancellationToken = default); // PDO Configuration Operations /// /// Ghi PDO configuration xuống device /// Device phải ở PreOperational state trước khi gọi method này /// Task WritePdoConfigurationToDeviceAsync(bool isTpdo, byte pdoNumber, CancellationToken cancellationToken = default); /// /// Ghi tất cả PDO configurations xuống device /// Device phải ở PreOperational state trước khi gọi method này /// /// Đường dẫn đến EDS file (optional, để check PDO support trước khi configure) /// Cancellation token Task WriteAllPdoConfigurationsToDeviceAsync(string? edsFilePath = null, CancellationToken cancellationToken = default); } public interface ICanBus : IDisposable { string InterfaceName { get; } bool IsConnected { get; } Task ConnectAsync(CancellationToken cancellationToken = default); Task DisconnectAsync(CancellationToken cancellationToken = default); Task SendFrameAsync(uint canId, byte[] data, CancellationToken cancellationToken = default); event EventHandler? FrameReceived; } public class CanFrameReceivedEventArgs(uint canId, byte[] data, DateTime timestamp) : EventArgs { public uint CanId { get; init; } = canId; public byte[] Data { get; init; } = data; public DateTime Timestamp { get; init; } = timestamp; }