Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/S7Tools.Core/Services/Interfaces/IBootloaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ public interface IBootloaderService
/// </summary>
/// <param name="profiles">Job profile set containing all configuration parameters.</param>
/// <param name="progress">Progress reporter providing stage name and completion percentage.</param>
/// <param name="taskLogger">Optional logger for main task operations and workflow steps.</param>
/// <param name="processLogger">Optional logger for capturing socat process stdout/stderr output.</param>
/// <param name="protocolLogger">Optional logger for capturing protocol-level PLC communication.</param>
/// <param name="cancellationToken">Cancellation token for the operation.</param>
/// <returns>The dumped memory data.</returns>
Task<byte[]> DumpAsync(
JobProfileSet profiles,
IProgress<(string stage, double percent)> progress,
Microsoft.Extensions.Logging.ILogger? taskLogger = null,
Microsoft.Extensions.Logging.ILogger? processLogger = null,
Microsoft.Extensions.Logging.ILogger? protocolLogger = null,
CancellationToken cancellationToken = default);

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions src/S7Tools.Core/Services/Interfaces/IPlcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ namespace S7Tools.Core.Services.Interfaces;
/// </summary>
public interface IPlcClient : IAsyncDisposable
{
/// <summary>
/// Sets the protocol logger for detailed communication logging.
/// </summary>
/// <param name="protocolLogger">Logger for protocol-level communication.</param>
void SetProtocolLogger(Microsoft.Extensions.Logging.ILogger? protocolLogger);

/// <summary>
/// Performs the initial handshake with the PLC bootloader.
/// </summary>
Expand Down
12 changes: 8 additions & 4 deletions src/S7Tools.Core/Services/Interfaces/IPowerSupplyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ public interface IPowerSupplyService
/// Connects to the power supply device using the specified configuration.
/// </summary>
/// <param name="configuration">The power supply configuration containing connection parameters.</param>
/// <param name="taskLogger">Optional logger for task-specific logging.</param>
/// <param name="cancellationToken">Cancellation token for the operation.</param>
/// <returns>A task representing the asynchronous operation. The task result indicates whether the connection was successful.</returns>
/// <exception cref="ArgumentNullException">Thrown when configuration is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when already connected or connection fails.</exception>
Task<bool> ConnectAsync(PowerSupplyConfiguration configuration, CancellationToken cancellationToken = default);
Task<bool> ConnectAsync(PowerSupplyConfiguration configuration, Microsoft.Extensions.Logging.ILogger? taskLogger = null, CancellationToken cancellationToken = default);

/// <summary>
/// Disconnects from the currently connected power supply device.
Expand Down Expand Up @@ -56,18 +57,20 @@ public interface IPowerSupplyService
/// <summary>
/// Turns the power supply on.
/// </summary>
/// <param name="taskLogger">Optional logger for task-specific logging.</param>
/// <param name="cancellationToken">Cancellation token for the operation.</param>
/// <returns>A task representing the asynchronous operation. The task result indicates whether the operation was successful.</returns>
/// <exception cref="InvalidOperationException">Thrown when not connected to a power supply device.</exception>
Task<bool> TurnOnAsync(CancellationToken cancellationToken = default);
Task<bool> TurnOnAsync(Microsoft.Extensions.Logging.ILogger? taskLogger = null, CancellationToken cancellationToken = default);

/// <summary>
/// Turns the power supply off.
/// </summary>
/// <param name="taskLogger">Optional logger for task-specific logging.</param>
/// <param name="cancellationToken">Cancellation token for the operation.</param>
/// <returns>A task representing the asynchronous operation. The task result indicates whether the operation was successful.</returns>
/// <exception cref="InvalidOperationException">Thrown when not connected to a power supply device.</exception>
Task<bool> TurnOffAsync(CancellationToken cancellationToken = default);
Task<bool> TurnOffAsync(Microsoft.Extensions.Logging.ILogger? taskLogger = null, CancellationToken cancellationToken = default);

/// <summary>
/// Reads the current power state from the power supply device.
Expand All @@ -81,10 +84,11 @@ public interface IPowerSupplyService
/// Performs a power cycle operation (turn off, wait, turn on).
/// </summary>
/// <param name="delayMs">The delay in milliseconds between power off and power on. Default is 5000ms (5 seconds).</param>
/// <param name="taskLogger">Optional logger for task-specific logging.</param>
/// <param name="cancellationToken">Cancellation token for the operation.</param>
/// <returns>A task representing the asynchronous operation. The task result indicates whether the operation was successful.</returns>
/// <exception cref="InvalidOperationException">Thrown when not connected to a power supply device.</exception>
Task<bool> PowerCycleAsync(int delayMs = 5000, CancellationToken cancellationToken = default);
Task<bool> PowerCycleAsync(int delayMs = 5000, Microsoft.Extensions.Logging.ILogger? taskLogger = null, CancellationToken cancellationToken = default);

#endregion

Expand Down
6 changes: 4 additions & 2 deletions src/S7Tools.Core/Services/Interfaces/ISerialPortService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,24 @@ public interface ISerialPortService
/// </summary>
/// <param name="portPath">The path to the serial port to configure.</param>
/// <param name="configuration">The configuration to apply to the port.</param>
/// <param name="taskLogger">Optional logger for task-specific logging.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>A task that represents the asynchronous operation. The task result indicates whether the configuration was applied successfully.</returns>
/// <exception cref="ArgumentException">Thrown when portPath is null/empty or configuration is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when the port is not accessible or stty command fails.</exception>
Task<bool> ApplyConfigurationAsync(string portPath, SerialPortConfiguration configuration, CancellationToken cancellationToken = default);
Task<bool> ApplyConfigurationAsync(string portPath, SerialPortConfiguration configuration, Microsoft.Extensions.Logging.ILogger? taskLogger = null, CancellationToken cancellationToken = default);

/// <summary>
/// Applies a profile to a serial port.
/// </summary>
/// <param name="portPath">The path to the serial port to configure.</param>
/// <param name="profile">The profile to apply to the port.</param>
/// <param name="taskLogger">Optional logger for task-specific logging.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>A task that represents the asynchronous operation. The task result indicates whether the profile was applied successfully.</returns>
/// <exception cref="ArgumentException">Thrown when portPath is null/empty or profile is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when the port is not accessible or stty command fails.</exception>
Task<bool> ApplyProfileAsync(string portPath, SerialPortProfile profile, CancellationToken cancellationToken = default);
Task<bool> ApplyProfileAsync(string portPath, SerialPortProfile profile, Microsoft.Extensions.Logging.ILogger? taskLogger = null, CancellationToken cancellationToken = default);

/// <summary>
/// Creates a backup of the current port configuration before applying changes.
Expand Down
6 changes: 4 additions & 2 deletions src/S7Tools.Core/Services/Interfaces/ISocatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,27 @@ public interface ISocatService
/// <param name="configuration">The socat configuration to use.</param>
/// <param name="serialDevice">The serial device path to bridge.</param>
/// <param name="processLogger">Optional logger for capturing socat process stdout/stderr output.</param>
/// <param name="protocolLogger">Optional logger for capturing protocol-level communication logs.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains information about the started process.</returns>
/// <exception cref="ArgumentNullException">Thrown when configuration is null.</exception>
/// <exception cref="ArgumentException">Thrown when serialDevice is null or empty.</exception>
/// <exception cref="InvalidOperationException">Thrown when the process cannot be started or port is already in use.</exception>
Task<SocatProcessInfo> StartSocatAsync(SocatConfiguration configuration, string serialDevice, Microsoft.Extensions.Logging.ILogger? processLogger = null, CancellationToken cancellationToken = default);
Task<SocatProcessInfo> StartSocatAsync(SocatConfiguration configuration, string serialDevice, Microsoft.Extensions.Logging.ILogger? processLogger = null, Microsoft.Extensions.Logging.ILogger? protocolLogger = null, CancellationToken cancellationToken = default);

/// <summary>
/// Starts a socat process with the specified profile.
/// </summary>
/// <param name="profile">The socat profile to use.</param>
/// <param name="serialDevice">The serial device path to bridge.</param>
/// <param name="processLogger">Optional logger for capturing socat process stdout/stderr output.</param>
/// <param name="protocolLogger">Optional logger for capturing protocol-level communication logs.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains information about the started process.</returns>
/// <exception cref="ArgumentNullException">Thrown when profile is null.</exception>
/// <exception cref="ArgumentException">Thrown when serialDevice is null or empty.</exception>
/// <exception cref="InvalidOperationException">Thrown when the process cannot be started or port is already in use.</exception>
Task<SocatProcessInfo> StartSocatWithProfileAsync(SocatProfile profile, string serialDevice, Microsoft.Extensions.Logging.ILogger? processLogger = null, CancellationToken cancellationToken = default);
Task<SocatProcessInfo> StartSocatWithProfileAsync(SocatProfile profile, string serialDevice, Microsoft.Extensions.Logging.ILogger? processLogger = null, Microsoft.Extensions.Logging.ILogger? protocolLogger = null, CancellationToken cancellationToken = default);

/// <summary>
/// Stops a running socat process.
Expand Down
8 changes: 8 additions & 0 deletions src/S7Tools/Services/Adapters/PlcClientAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace S7Tools.Services.Adapters
public sealed class PlcClientAdapter : IPlcClient
{
private readonly ILogger<PlcClientAdapter> _logger;
private ILogger? _protocolLogger;
private readonly IPlcProtocol _protocol;

// Components
Expand All @@ -33,6 +34,13 @@ public PlcClientAdapter(IPlcProtocol protocol, ILogger<PlcClientAdapter> logger)
_stagerManager = new PlcStagerManager(_protocolHandler, _memoryManager);
}

public void SetProtocolLogger(ILogger? protocolLogger)
{
_protocolLogger = protocolLogger;
// TODO: Protocol logger can be used for detailed hex dumps of PLC communication
// For now, store it for future implementation
}

public void Configure(string host, int port)
{
_protocol.Configure(host, port);
Expand Down
Loading