Skip to content

Commit

Permalink
Improved F15 integration
Browse files Browse the repository at this point in the history
Added F15 intercom radio volume
Improved MIDS handling to support MIDS channel files or if none is present - a list is generated for you
Added a button to generate a Radio Frequency file ready for adding in entries
Added door open / door closed for OH58D (need to add audio)
Updated Resources with the new resource for the create button
  • Loading branch information
ciribob committed May 4, 2024
1 parent 74d434f commit c047827
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 25 deletions.
9 changes: 9 additions & 0 deletions DCS-SR-Client/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions DCS-SR-Client/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1160,4 +1160,7 @@ Requires Tx or Rx Effects On</value>
<data name="VOXModeLower" xml:space="preserve">
<value>Lower</value>
</data>
<data name="OverlayPresetCreate" xml:space="preserve">
<value>Create</value>
</data>
</root>
3 changes: 3 additions & 0 deletions DCS-SR-Client/Properties/Resources.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ https://github.com/ciribob/DCS-SimpleRadioStandalone/releases/latest</value>
<data name="OverlayNotAvailable" xml:space="preserve">
<value>不可用 - 仅限SRS浮窗控制</value>
</data>
<data name="OverlayPresetCreate" xml:space="preserve">
<value>创造</value>
</data>
<data name="OverlayPresetReload" xml:space="preserve">
<value>重新加载</value>
</data>
Expand Down
92 changes: 90 additions & 2 deletions DCS-SR-Client/Settings/RadioChannels/FilePresetChannelsStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Ciribob.DCS.SimpleRadio.Standalone.Client.UI.ClientWindow.PresetChannels;
using Newtonsoft.Json.Linq;
using NLog;

namespace Ciribob.DCS.SimpleRadio.Standalone.Client.Settings.RadioChannels
Expand All @@ -15,18 +16,46 @@ public class FilePresetChannelsStore : IPresetChannelsStore
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

public IEnumerable<PresetChannel> LoadFromStore(string radioName)
public IEnumerable<PresetChannel> LoadFromStore(string radioName, bool mids = false)
{
var file = FindRadioFile(NormaliseString(radioName));

if (file != null)
{
return ReadFrequenciesFromFile(file);
if (mids)
{
return ReadMidsFrequenciesFromFile(file);
}
else
{
return ReadFrequenciesFromFile(file);
}
}

return new List<PresetChannel>();
}

public void CreatePresetFile(string radioName)
{
var file = FindRadioFile(NormaliseString(radioName));

if (file == null)
{
var path = Environment.CurrentDirectory + Path.DirectorySeparatorChar +
NormaliseString(radioName) + ".txt";
try
{
File.Create(path);
Logger.Log(LogLevel.Info, $"Created radio file {path} ");
}
catch
{
Logger.Log(LogLevel.Error, $"Error creating radio file {path} ");
}

}
}

private List<PresetChannel> ReadFrequenciesFromFile(string filePath)
{
List<PresetChannel> channels = new List<PresetChannel>();
Expand Down Expand Up @@ -81,6 +110,65 @@ private List<PresetChannel> ReadFrequenciesFromFile(string filePath)
return channels;
}

private List<PresetChannel> ReadMidsFrequenciesFromFile(string filePath)
{

List<PresetChannel> channels = new List<PresetChannel>();
string[] lines = File.ReadAllLines(filePath);

const double MHz = ( 100000.0);
const double MidsOffsetMHz = (1030.0 * 1000000.0);
if (lines?.Length > 0)
{
foreach (var line in lines)
{
var trimmed = line.Trim();
if (trimmed.Length > 0)
{
try
{
var split = trimmed.Split('|');

var name = "";
int midsChannel = 0;
if (split.Length >= 2)
{
name = split[0];
midsChannel = Int32.Parse(split[1], CultureInfo.InvariantCulture);
}
else
{
name = trimmed;
midsChannel = Int32.Parse(trimmed, CultureInfo.InvariantCulture);
}

if (midsChannel > 0 && midsChannel < 126)
{
channels.Add(new PresetChannel()
{
Text = name + " | "+midsChannel,
Value = (midsChannel * MHz) + MidsOffsetMHz
});
}
}
catch (Exception)
{
Logger.Log(LogLevel.Info, "Error parsing frequency " + trimmed);
}
}
}
}

int i = 1;
foreach (var channel in channels)
{
channel.Text = i + " - " + channel.Text;
i++;
}

return channels;
}

private string FindRadioFile(string radioName)
{
var files = Directory.GetFiles(Environment.CurrentDirectory);
Expand Down
4 changes: 3 additions & 1 deletion DCS-SR-Client/Settings/RadioChannels/IPresetChannelsStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Ciribob.DCS.SimpleRadio.Standalone.Client.Settings.RadioChannels
{
public interface IPresetChannelsStore
{
IEnumerable<PresetChannel> LoadFromStore(string radioName);
IEnumerable<PresetChannel> LoadFromStore(string radioName, bool mids = false);

void CreatePresetFile(string radioName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Ciribob.DCS.SimpleRadio.Standalone.Client.Settings.RadioChannels
{
public class MockPresetChannelsStore : IPresetChannelsStore
{
public IEnumerable<PresetChannel> LoadFromStore(string radioName)
public IEnumerable<PresetChannel> LoadFromStore(string radioName, bool mids = false)
{
IList<PresetChannel> _presetChannels = new List<PresetChannel>();

Expand All @@ -34,5 +34,10 @@ public IEnumerable<PresetChannel> LoadFromStore(string radioName)

return _presetChannels;
}

public void CreatePresetFile(string radioName)
{
//nothing
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
d:DesignHeight="100"
d:DesignWidth="135"
mc:Ignorable="d">
<WrapPanel HorizontalAlignment="Center"
<StackPanel HorizontalAlignment="Center"
Background="#444"
Orientation="Vertical">
<ComboBox x:Name="FrequencyDropDown"
Expand All @@ -24,14 +24,25 @@
ItemsSource="{Binding Path=PresetChannels}"
SelectedItem="{Binding Path=SelectedPresetChannel}" />

<Button Name="ReloadButton"
<StackPanel HorizontalAlignment="Center"
Background="#444"
Orientation="Horizontal">
<Button Name="ReloadButton"
Width="50"
Height="20"
Margin="0,5,0,0"
Margin="2"
HorizontalAlignment="Center"
Command="{Binding Path=ReloadCommand}"
Content="{x:Static p:Resources.OverlayPresetReload}"
Style="{x:Null}" />

</WrapPanel>
<Button Name="CreateButton"
Width="50"
Height="20"
Margin="2"
HorizontalAlignment="Center"
Command="{Binding Path=PresetCreateCommand}"
Content="{x:Static p:Resources.OverlayPresetCreate}"
Style="{x:Null}" />
</StackPanel>
</StackPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Windows.Data;
using System.Windows.Input;
using Ciribob.DCS.SimpleRadio.Standalone.Client.Settings.RadioChannels;
Expand All @@ -18,6 +19,8 @@ public class PresetChannelsViewModel

public DelegateCommand DropDownClosedCommand { get; set; }

public DelegateCommand PresetCreateCommand { get; set; }


private readonly object _presetChannelLock = new object();
private ObservableCollection<PresetChannel> _presetChannels;
Expand Down Expand Up @@ -49,6 +52,7 @@ public PresetChannelsViewModel(IPresetChannelsStore channels, int radioId)
ReloadCommand = new DelegateCommand(OnReload);
DropDownClosedCommand = new DelegateCommand(DropDownClosed);
PresetChannels = new ObservableCollection<PresetChannel>();
PresetCreateCommand = new DelegateCommand(CreatePreset);
}


Expand Down Expand Up @@ -92,16 +96,25 @@ public void Reload()
}
else
{
//SR.MIDS_FREQ = 1030.0 * 1000000-- Start at UHF 10300
// SR.MIDS_FREQ_SEPARATION = 1.0 * 100000-- 0.1 MHZ between MIDS channels
for (int i = 1; i < 127; i++)

int i = 1;
foreach (var channel in _channelsStore.LoadFromStore(radio.name,true))
{
channel.Channel = i++;
PresetChannels.Add(channel);
}

if (PresetChannels.Count == 0)
{
PresetChannels.Add(new PresetChannel
for (int chn = 1; chn < 126; chn++)
{
Channel = i,
Text = "MIDS " + i,
Value = (i * 100000.0) + (1030.0 * 1000000.0)
});
PresetChannels.Add(new PresetChannel
{
Channel = chn,
Text = "MIDS " + chn,
Value = (chn * 100000.0) + (1030.0 * 1000000.0)
});
}
}
}
}
Expand All @@ -111,6 +124,18 @@ private void OnReload()
Reload();
}

private void CreatePreset()
{
var radios = ClientStateSingleton.Instance.DcsPlayerRadioInfo.radios;

var radio = radios[_radioId];

if (radio.modulation != RadioInformation.Modulation.DISABLED && radio.modulation != RadioInformation.Modulation.INTERCOM)
{
_channelsStore.CreatePresetFile(radio.name);
}
}

public void Clear()
{
PresetChannels.Clear();
Expand Down
20 changes: 17 additions & 3 deletions DCS-SR-Client/Utils/RadioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Ciribob.DCS.SimpleRadio.Standalone.Client.Singletons;
using Ciribob.DCS.SimpleRadio.Standalone.Client.UI.ClientWindow.PresetChannels;
using Ciribob.DCS.SimpleRadio.Standalone.Common;
using MathNet.Numerics.Distributions;

namespace Ciribob.DCS.SimpleRadio.Standalone.Client.Utils
{
Expand Down Expand Up @@ -141,6 +142,7 @@ public static bool UpdateRadioFrequency(double frequency, int radioId, bool delt
return inLimit;
}


public static bool SelectRadio(int radioId)
{
var radio = GetRadio(radioId);
Expand Down Expand Up @@ -327,12 +329,24 @@ public static void DecreaseEncryptionKey(int radioId)

public static void SelectRadioChannel(PresetChannel selectedPresetChannel, int radioId)
{
if (UpdateRadioFrequency((double) selectedPresetChannel.Value, radioId, false, false))

var radio = GetRadio(radioId);

if (radio != null && radioId > 0)
{
var radio = GetRadio(radioId);
if (radio.modulation != RadioInformation.Modulation.DISABLED
&& radio.modulation != RadioInformation.Modulation.INTERCOM
&& radio.freqMode == RadioInformation.FreqMode.OVERLAY)
{

radio.freq = (double)selectedPresetChannel.Value;
radio.channel = selectedPresetChannel.Channel;

if (radio != null) radio.channel = selectedPresetChannel.Channel;
//make radio data stale to force resysnc
ClientStateSingleton.Instance.LastSent = 0;
}
}

}

public static void RadioChannelUp(int radioId)
Expand Down
Loading

0 comments on commit c047827

Please sign in to comment.