|
|
|
|
@ -22,6 +22,9 @@ namespace dvmusrp
|
|
|
|
|
public class NetworkDVM : Network
|
|
|
|
|
{
|
|
|
|
|
private NetworkUSRP usrpNetwork;
|
|
|
|
|
private DateTime lastPacketReceivedTime;
|
|
|
|
|
private TimeSpan callTimeout = TimeSpan.FromSeconds(1);
|
|
|
|
|
private bool eotSent = false;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates an instance of <see cref="NetworkDVM"/>
|
|
|
|
|
@ -30,7 +33,10 @@ namespace dvmusrp
|
|
|
|
|
/// <param name="sendPort"></param>
|
|
|
|
|
/// <param name="receiveAddress"></param>
|
|
|
|
|
/// <param name="sendAddress"></param>
|
|
|
|
|
public NetworkDVM(int receivePort, int sendPort, string receiveAddress, string sendAddress) : base(receivePort, sendPort, receiveAddress, sendAddress) { }
|
|
|
|
|
public NetworkDVM(int receivePort, int sendPort, string receiveAddress, string sendAddress) : base(receivePort, sendPort, receiveAddress, sendAddress)
|
|
|
|
|
{
|
|
|
|
|
lastPacketReceivedTime = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Helper to set the instance of <see cref="NetworkUSRP"/>
|
|
|
|
|
@ -54,9 +60,26 @@ namespace dvmusrp
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var receivedResult = await udpClient.ReceiveAsync();
|
|
|
|
|
Task<UdpReceiveResult> receivedTask = udpClient.ReceiveAsync();
|
|
|
|
|
Task timeoutTask = Task.Delay(callTimeout);
|
|
|
|
|
|
|
|
|
|
Task completedTask = await Task.WhenAny(receivedTask, timeoutTask);
|
|
|
|
|
|
|
|
|
|
if (completedTask == timeoutTask)
|
|
|
|
|
{
|
|
|
|
|
if (!eotSent)
|
|
|
|
|
{
|
|
|
|
|
SendUsrpEOT();
|
|
|
|
|
eotSent = true;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ForwardToUSRP(receivedResult.Buffer);
|
|
|
|
|
eotSent = false;
|
|
|
|
|
|
|
|
|
|
lastPacketReceivedTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
ForwardToUSRP(receivedTask.Result.Buffer);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
@ -91,6 +114,8 @@ namespace dvmusrp
|
|
|
|
|
Array.Copy(packet, 4, audio, 0, audio.Length); // No meta data, just skip PCM length
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usrpHeader[15] = 1; // Set PTT state to on
|
|
|
|
|
|
|
|
|
|
Array.Copy(Encoding.ASCII.GetBytes("USRP"), usrpHeader, 4);
|
|
|
|
|
Array.Copy(usrpHeader, usrpData, usrpHeader.Length);
|
|
|
|
|
Array.Copy(audio, 0, usrpData, 32, audio.Length);
|
|
|
|
|
@ -100,6 +125,17 @@ namespace dvmusrp
|
|
|
|
|
usrpNetwork.SendData(usrpData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Helper to send a EOT to USRP
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SendUsrpEOT()
|
|
|
|
|
{
|
|
|
|
|
byte[] usrpHeader = new byte[32];
|
|
|
|
|
Array.Copy(Encoding.ASCII.GetBytes("USRP"), usrpHeader, 4);
|
|
|
|
|
|
|
|
|
|
usrpNetwork.SendData(usrpHeader);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Helper to send data to DVM
|
|
|
|
|
/// </summary>
|
|
|
|
|
|