using System.Threading;
using System.Threading.Tasks;
namespace EM.LowLevel
{
///
/// Generic high-level controller that composes a PortStream, an ICommandBuilder and an
/// IDataDecoder to provide a complete peripheral control workflow.
///
///
/// Concrete transport deriving from PortStream
///
///
/// Concrete command builder
///
///
/// Concrete data decoder
///
public interface IPortController where TPort: PortStream where TBuilder: ICommandBuilder
where TDecoder: IDataDecoder
{
TBuilder CommandBuilder { get; }
TDecoder Decoder { get; }
TPort Port { get; }
///
/// Close the underlying port.
///
void Close();
///
/// Ensure the underlying port is opened and ready (delegates to Port.OpenAsync).
///
ValueTask OpenAsync(CancellationToken cancellationToken = default);
///
/// Build a command, send it via the port and decode the response into a model.
///
ValueTask RoundTripAsync(
TCommand command,
CancellationToken cancellationToken = default)
where TCommand: notnull;
///
/// Build a command and send it without expecting a typed response.
///
ValueTask WriteAsync(TCommand command, CancellationToken cancellationToken = default)
where TCommand: notnull;
}
}