Files
testcan/CanCommon/ICanChannel.cs
2026-08-20 14:56:23 +07:00

34 lines
1.2 KiB
C#

namespace CanCommon;
/// <summary>
/// Backend-agnostic CAN channel. The benchmark depends only on this interface,
/// so the exact same benchmark code runs against any implementation
/// (SocketCAN / PEAK PCAN-Basic / a vendor CAN module) by swapping the backend.
/// Frames are raw 16-byte SocketCAN <c>can_frame</c> buffers (see <see cref="CanFrame"/>).
/// </summary>
public interface ICanChannel : IDisposable
{
/// <summary>Human-readable channel name (e.g. the network interface).</summary>
string Name { get; }
/// <summary>errno from the most recent failed native call (0 if none).</summary>
int LastErrno { get; }
/// <summary>Open and bind the channel. Throws on failure.</summary>
void Open();
/// <summary>
/// Transmit one 16-byte frame. Returns true when fully written.
/// On false, <see cref="LastErrno"/> holds the reason (e.g. bus-off / no-buffer).
/// </summary>
bool Send(byte[] frame16);
/// <summary>
/// Blocking receive with the channel's configured timeout.
/// Returns 16 on a frame, 0 on timeout, -1 on error.
/// </summary>
int Receive(byte[] frame16, out bool timedOut);
void Close();
}