Add multi channel PTT; add channel marker; other small fixes

pull/1/head
firealarmss 11 months ago
parent 209aadd0db
commit d5c4ee07fc

@ -54,6 +54,8 @@ namespace WhackerLinkConsoleV2.Controls
public string SystemName { get; set; }
public string DstId { get; set; }
public bool IsReceiving { get; set; } = false;
public string LastSrcId
{
get => _lastSrcId;

@ -79,7 +79,7 @@
</Button.Background>
</Button>
<Image HorizontalAlignment="Left" Margin="353,3,0,3" Grid.Row="1" Width="37" Source="/alerttone.png" IsHitTestVisible="False"/>
<Button VerticalContentAlignment="Bottom" HorizontalAlignment="Left" Margin="170,0,0,0" VerticalAlignment="Center" Height="46" Width="82" Click="Button_Click" BorderBrush="#FFC1C1C1" BorderThickness="1,1,1,1" Grid.Row="1" FontSize="10" FontFamily="Arial">
<Button VerticalContentAlignment="Bottom" HorizontalAlignment="Left" Margin="170,0,0,0" x:Name="btnGlobalPtt" VerticalAlignment="Center" Height="46" Width="82" Click="btnGlobalPtt_Click" BorderBrush="#FFC1C1C1" BorderThickness="1,1,1,1" Grid.Row="1" FontSize="10" FontFamily="Arial">
<Button.Resources>
<Style TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="2"/>

@ -21,6 +21,7 @@
using Microsoft.Win32;
using System;
using System.Timers;
using System.IO;
using System.Windows;
using System.Windows.Controls;
@ -41,6 +42,8 @@ using Nancy;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar;
using System.Media;
using System.Threading.Tasks;
using static WhackerLinkLib.Models.Radio.Codeplug;
namespace WhackerLinkConsoleV2
{
@ -49,6 +52,8 @@ namespace WhackerLinkConsoleV2
public Codeplug Codeplug { get; set; }
private bool isEditMode = false;
private bool globalPttState = false;
private UIElement _draggedElement;
private Point _startPoint;
private double _offsetX;
@ -64,6 +69,8 @@ namespace WhackerLinkConsoleV2
private readonly WaveInEvent _waveIn;
private readonly AudioManager _audioManager;
private static System.Timers.Timer _channelHoldTimer;
public MainWindow()
{
#if DEBUG
@ -75,6 +82,11 @@ namespace WhackerLinkConsoleV2
_flashingManager = new FlashingBackgroundManager(null, ChannelsCanvas, null, this);
_emergencyAlertPlayback = new WaveFilePlaybackManager(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "emergency.wav"));
_channelHoldTimer = new System.Timers.Timer(10000);
_channelHoldTimer.Elapsed += OnHoldTimerElapsed;
_channelHoldTimer.AutoReset = true;
_channelHoldTimer.Enabled = true;
_waveIn = new WaveInEvent
{
WaveFormat = new WaveFormat(8000, 16, 1)
@ -488,13 +500,11 @@ namespace WhackerLinkConsoleV2
private void SendAlertTone(AlertTone e)
{
Task.Run(() => SendAlertTone(e.AlertFilePath));
Task.Factory.StartNew(() => SendAlertTone(e.AlertFilePath));
}
private async void SendAlertTone(string filePath)
private void SendAlertTone(string filePath, bool forHold = false)
{
Console.WriteLine(filePath);
Console.WriteLine(File.Exists(filePath));
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
{
try
@ -505,10 +515,11 @@ namespace WhackerLinkConsoleV2
Codeplug.Channel cpgChannel = Codeplug.GetChannelByName(channel.ChannelName);
IPeer handler = _webSocketManager.GetWebSocketHandler(system.Name);
if (channel.PageState)
if (channel.PageState || (forHold && channel.HoldState))
{
byte[] pcmData;
Task.Factory.StartNew(async () => {
using (var waveReader = new WaveFileReader(filePath))
{
if (waveReader.WaveFormat.Encoding != WaveFormatEncoding.Pcm ||
@ -575,7 +586,7 @@ namespace WhackerLinkConsoleV2
}
}
double totalDurationMs = ((double)pcmData.Length / 16000) * 1000 - 6000;
double totalDurationMs = ((double)pcmData.Length / 16000);
await Task.Delay((int)totalDurationMs);
GRP_VCH_RLS release = new GRP_VCH_RLS
@ -586,11 +597,16 @@ namespace WhackerLinkConsoleV2
Site = system.Site
};
handler.SendMessage(release.GetData());
Dispatcher.Invoke(() =>
{
channel.PageSelectButton.Background = channel.grayGradient;
handler.SendMessage(release.GetData());
if (forHold)
channel.PttButton.Background = channel.grayGradient;
else
channel.PageState = false;
});
});
}
}
@ -711,9 +727,15 @@ namespace WhackerLinkConsoleV2
Dispatcher.Invoke(() =>
{
if (channel.IsSelected)
{
channel.Background = (Brush)new BrushConverter().ConvertFrom("#FF0B004B");
channel.IsReceiving = false;
}
else
{
channel.Background = new SolidColorBrush(Colors.DarkGray);
channel.IsReceiving = false;
}
});
channel.VoiceChannel = null;
@ -739,8 +761,9 @@ namespace WhackerLinkConsoleV2
Dispatcher.Invoke(() =>
{
channel.Background = (Brush)new BrushConverter().ConvertFrom("#FF00BC48");
channel.IsReceiving = true;
});
} else if (channel.PageState && response.Status == (int)ResponseType.GRANT && response.Channel != null && response.SrcId == system.Rid && response.DstId == cpgChannel.Tgid)
} else if ((channel.HoldState || channel.PageState) && response.Status == (int)ResponseType.GRANT && response.Channel != null && response.SrcId == system.Rid && response.DstId == cpgChannel.Tgid)
{
channel.VoiceChannel = response.Channel;
}
@ -847,7 +870,7 @@ namespace WhackerLinkConsoleV2
element.CaptureMouse();
}
private const int GridSize = 5; // Set grid size (adjust as needed)
private const int GridSize = 5;
private void ChannelBox_MouseMove(object sender, MouseEventArgs e)
{
@ -876,7 +899,6 @@ namespace WhackerLinkConsoleV2
AdjustCanvasHeight();
}
private void ChannelBox_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
if (!isEditMode || !_isDragging || _draggedElement == null) return;
@ -1009,6 +1031,39 @@ namespace WhackerLinkConsoleV2
}
}
private async void OnHoldTimerElapsed(object sender, ElapsedEventArgs e)
{
foreach (ChannelBox channel in _selectedChannelsManager.GetSelectedChannels())
{
Codeplug.System system = Codeplug.GetSystemForChannel(channel.ChannelName);
Codeplug.Channel cpgChannel = Codeplug.GetChannelByName(channel.ChannelName);
IPeer handler = _webSocketManager.GetWebSocketHandler(system.Name);
if (channel.HoldState && !channel.IsReceiving && !channel.PttState && !channel.PageState)
{
//Task.Factory.StartNew(async () =>
//{
Console.WriteLine("Sending channel hold beep");
Dispatcher.Invoke(() => { channel.PttButton.Background = channel.redGradient; });
GRP_VCH_REQ req = new GRP_VCH_REQ
{
SrcId = system.Rid,
DstId = cpgChannel.Tgid,
Site = system.Site
};
handler.SendMessage(req.GetData());
await Task.Delay(1000);
SendAlertTone("hold.wav", true);
// });
}
}
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
_settingsManager.SaveSettings();
@ -1049,6 +1104,58 @@ namespace WhackerLinkConsoleV2
});
}
private void btnGlobalPtt_Click(object sender, RoutedEventArgs e)
{
globalPttState = !globalPttState;
foreach (ChannelBox channel in _selectedChannelsManager.GetSelectedChannels())
{
Codeplug.System system = Codeplug.GetSystemForChannel(channel.ChannelName);
Codeplug.Channel cpgChannel = Codeplug.GetChannelByName(channel.ChannelName);
IPeer handler = _webSocketManager.GetWebSocketHandler(system.Name);
if (!channel.IsSelected)
return;
if (globalPttState)
{
Dispatcher.Invoke(() =>
{
btnGlobalPtt.Background = channel.redGradient;
});
GRP_VCH_REQ request = new GRP_VCH_REQ
{
SrcId = system.Rid,
DstId = cpgChannel.Tgid,
Site = system.Site
};
channel.PttState = true;
handler.SendMessage(request.GetData());
} else
{
Dispatcher.Invoke(() =>
{
btnGlobalPtt.Background = channel.grayGradient;
});
GRP_VCH_RLS release = new GRP_VCH_RLS
{
SrcId = system.Rid,
DstId = cpgChannel.Tgid,
Site = system.Site
};
channel.PttState = false;
handler.SendMessage(release.GetData());
}
}
}
private void Button_Click(object sender, RoutedEventArgs e) { /* sub */ }
}
}

Loading…
Cancel
Save

Powered by TurnKey Linux.