Skip to content
Closed
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: 2 additions & 2 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ jobs:
dotnet tool install --global dotnet-sonarscanner
echo "$env:USERPROFILE\.dotnet\tools" >> $env:GITHUB_PATH
dotnet sonarscanner begin `
/k:"ppanchen_NetSdrClient" `
/o:"ppanchen" `
/k:"AntAndriy7_ReengineeringCourse" `
/o:"antandriy7" `
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" `
/d:sonar.cs.opencover.reportsPaths="**/coverage.xml" `
/d:sonar.cpd.cs.minimumTokens=40 `
Expand Down
19 changes: 10 additions & 9 deletions NetSdrClientApp/NetSdrClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
Expand All @@ -14,8 +15,10 @@ namespace NetSdrClientApp
{
public class NetSdrClient
{
private ITcpClient _tcpClient;
private IUdpClient _udpClient;
private readonly ITcpClient _tcpClient;
private readonly IUdpClient _udpClient;

private TaskCompletionSource<byte[]>? _responseTaskSource;

public bool IQStarted { get; set; }

Expand Down Expand Up @@ -131,8 +134,6 @@ private void _udpClient_MessageReceived(object? sender, byte[] e)
}
}

private TaskCompletionSource<byte[]> responseTaskSource;

private async Task<byte[]> SendTcpRequest(byte[] msg)
{
if (!_tcpClient.Connected)
Expand All @@ -141,8 +142,8 @@ private async Task<byte[]> SendTcpRequest(byte[] msg)
return null;
}

responseTaskSource = new TaskCompletionSource<byte[]>(TaskCreationOptions.RunContinuationsAsynchronously);
var responseTask = responseTaskSource.Task;
_responseTaskSource = new TaskCompletionSource<byte[]>(TaskCreationOptions.RunContinuationsAsynchronously);
var responseTask = _responseTaskSource.Task;

await _tcpClient.SendMessageAsync(msg);

Expand All @@ -154,10 +155,10 @@ private async Task<byte[]> SendTcpRequest(byte[] msg)
private void _tcpClient_MessageReceived(object? sender, byte[] e)
{
//TODO: add Unsolicited messages handling here
if (responseTaskSource != null)
if (_responseTaskSource != null)
{
responseTaskSource.SetResult(e);
responseTaskSource = null;
_responseTaskSource.SetResult(e);
_responseTaskSource = null;
}
Console.WriteLine("Response recieved: " + e.Select(b => Convert.ToString(b, toBase: 16)).Aggregate((l, r) => $"{l} {r}"));
}
Expand Down